summaryrefslogtreecommitdiff
path: root/test/invite.et
blob: 52f2c8bb0632f3b3d112e5f1f608305888bff090 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
module invite

import common

test InviteContact:
    let services = "contact,invite"

    spawn as p1
    spawn as p2

    send "create-identity Device1 Owner1" to p1
    expect /create-identity-done ref ($refpat)/ from p1 capture p1id
    send "identity-info $p1id" to p1
    expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner
    send "identity-info $p1owner" to p1
    expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase

    send "create-identity Device2 Owner2" to p2
    expect /create-identity-done ref ($refpat)/ from p2 capture p2id

    send "start-server services $services" to p1
    send "start-server services $services" to p2

    expect from p1:
        /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2
        /peer $peer1_2 id Device2 Owner2/

    expect from p2:
        /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1
        /peer $peer2_1 id Device1 Owner1/

    send "invite-contact-create Contact2" to p1
    expect from p1 /invite-contact-create-done ([^ ]+)/ capture token

    with p2:
        send "invite-accept 00 $p1obase"
        expect /invite-accept-done 00/
        expect /invite-reply 00 invalid/

        send "contact-list"
        expect:
            /contact-list-(.*)/ capture done
        guard (done == "done")

    with p2:
        send "invite-accept $token $p1obase"
        expect /invite-accept-done $token/
        expect /invite-reply $token contact/

        send "contact-list"
        expect:
            /contact-list-item [a-z0-9#]+ Owner1 Owner1/
            /contact-list-(.*)/ capture done
        guard (done == "done")

    with p2:
        send "invite-accept $token $p1obase"
        expect /invite-accept-done $token/
        expect /invite-reply $token invalid/

        send "contact-list"
        expect:
            /contact-list-item [a-z0-9#]+ Owner1 Owner1/
            /contact-list-(.*)/ capture done
        guard (done == "done")

    with p1:
        expect /invite-accepted $token $p2id/

        send "contact-list"
        expect:
            /contact-list-item [a-z0-9#]+ Contact2 Owner2/
            /contact-list-(.*)/ capture done
        guard (done == "done")


test InviteContactDelayed:
    let services = "contact,invite"

    subnet s1
    subnet s2

    spawn as p1 on s1
    spawn as p2 on s2

    send "create-identity Device1 Owner1" to p1
    expect /create-identity-done ref ($refpat)/ from p1 capture p1id
    send "identity-info $p1id" to p1
    expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner
    send "identity-info $p1owner" to p1
    expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase

    send "create-identity Device2 Owner2" to p2
    expect /create-identity-done ref ($refpat)/ from p2 capture p2id

    send "start-server services $services" to p1
    send "start-server services $services" to p2

    send "invite-contact-create Contact2" to p1
    expect from p1 /invite-contact-create-done ([^ ]+)/ capture token

    with p2:
        send "invite-accept $token $p1obase"
        expect /invite-accept-done $token/

    send to p2 "peer-add ${p1.node.ip}"

    expect from p1:
        /peer ([0-9]+) addr ${p2.node.ip} 29665/ capture peer1_2
        /peer $peer1_2 id Device2 Owner2/

    expect from p2:
        /peer ([0-9]+) addr ${p1.node.ip} 29665/ capture peer2_1
        /peer $peer2_1 id Device1 Owner1/

    with p2:
        expect /invite-reply $token contact/

        send "contact-list"
        expect:
            /contact-list-item [a-z0-9#]+ .*/
            /contact-list-(.*)/ capture done
        guard (done == "done")

    with p1:
        expect /invite-accepted $token $refpat/

        send "contact-list"
        expect:
            /contact-list-item [a-z0-9#]+ Contact2 .*/
            /contact-list-(.*)/ capture done
        guard (done == "done")


test InviteContactDiscovery:
    let services = "contact,invite,discovery"

    subnet sd
    subnet s1
    subnet s2

    spawn as pd on sd
    spawn as p1 on s1
    spawn as p2 on s2

    send "create-identity Discovery" to pd
    expect /create-identity-done ref $refpat.*/ from pd

    send "create-identity Device1 Owner1" to p1
    expect /create-identity-done ref ($refpat)/ from p1 capture p1id
    send "identity-info $p1id" to p1
    expect /identity-info ref $p1id base ($refpat) owner ($refpat).*/ from p1 capture p1base, p1owner
    send "identity-info $p1owner" to p1
    expect /identity-info ref $p1owner base ($refpat).*/ from p1 capture p1obase

    send "create-identity Device2 Owner2" to p2
    expect /create-identity-done ref ($refpat)/ from p2 capture p2id

    send "start-server services discovery" to pd
    send "start-server services $services" to p1
    send "start-server services $services" to p2

    for p in [ p1, p2 ]:
        with p:
            send "peer-add ${pd.node.ip}"
            expect:
                /peer 1 addr ${pd.node.ip} 29665/
                /peer 1 id Discovery/
        expect from pd:
                /peer [12] addr ${p.node.ip} 29665/
                /peer [12] id .*/

    send "invite-contact-create Contact2" to p1
    expect from p1 /invite-contact-create-done ([^ ]+)/ capture token

    with p2:
        send "invite-accept $token $p1obase"
        expect /invite-accept-done $token/
        expect /invite-reply $token contact/

        send "contact-list"
        expect:
            /contact-list-item [a-z0-9#]+ .*/
            /contact-list-(.*)/ capture done
        guard (done == "done")

    with p1:
        expect /invite-accepted $token $refpat/

        send "contact-list"
        expect:
            /contact-list-item [a-z0-9#]+ Contact2 .*/
            /contact-list-(.*)/ capture done
        guard (done == "done")