-
Notifications
You must be signed in to change notification settings - Fork 8
/
find_dapper_test.go
369 lines (323 loc) · 11 KB
/
find_dapper_test.go
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
package test_main
import (
"testing"
. "github.com/bjartek/overflow"
"github.com/hexops/autogold"
)
/*
Tests must be in the same folder as flow.json with contracts and transactions/scripts in subdirectories in order for the path resolver to work correctly
*/
func TestDapperFIND(t *testing.T) {
otu := NewOverflowTest(t).
setupFIND().
createDapperUser("user1").
registerDapperUser("user1")
t.Run("Should be able to register a name", func(t *testing.T) {
// Can fix this with pointerWant
otu.O.Script("getLeases").AssertWithPointerWant(t, "/0/name",
autogold.Want("allLeases", "user1"),
)
})
t.Run("Should get expected output for register script", func(t *testing.T) {
otu.O.Script("getMetadataForRegisterDapper",
WithArg("merchAccount", "find"),
WithArg("name", "user2"),
WithArg("amount", 5.0),
).AssertWant(t, autogold.Want("getMetadataForRegisterDapper", map[string]interface{}{
"amount": 5, "description": "Name :user2 for DUC 5.00000000",
"id": 0,
"imageURL": "https://ik.imagekit.io/xyvsisxky/tr:ot-user2,ots-55,otc-58B792,ox-N166,oy-N24,ott-b/https://i.imgur.com/8W8NoO1.png",
"name": "user2",
}))
})
t.Run("Should get error if you try to register a name that is too short", func(t *testing.T) {
otu.O.Tx("devRegisterDapper",
WithSigner("user1"),
WithPayloadSigner("dapper"),
WithArg("merchAccount", "find"),
WithArg("name", "ur"),
WithArg("amount", 5.0),
).AssertFailure(t, "A FIND name has to be lower-cased alphanumeric or dashes and between 3 and 16 characters")
})
t.Run("Should get error if you try to register a name that is already claimed", func(t *testing.T) {
otu.O.Tx("devRegisterDapper",
WithSigner("user1"),
WithPayloadSigner("dapper"),
WithArg("merchAccount", "dapper"),
WithArg("name", "user1"),
WithArg("amount", 5.0),
).AssertFailure(t, "Name already registered")
})
t.Run("Should allow registering a lease after it is freed", func(t *testing.T) {
otu.expireLease().tickClock(2.0)
otu.O.Tx(`
import FIND from "../contracts/FIND.cdc"
transaction(name: String) {
prepare(account: AuthAccount) {
let status=FIND.status(name)
if status.status == FIND.LeaseStatus.LOCKED {
panic("locked")
}
if status.status == FIND.LeaseStatus.FREE {
panic("free")
}
}
}
`,
WithSigner("user1"),
WithArg("name", "user1"),
).AssertFailure(t, "locked")
otu.expireLease()
otu.registerDapperUser("user1")
})
t.Run("Should be able to lookup address", func(t *testing.T) {
otu.assertLookupAddress("user1", otu.O.Address("user1"))
})
t.Run("Should not be able to lookup lease after expired", func(t *testing.T) {
otu.expireLease().
tickClock(2.0)
otu.O.Script("getNameStatus",
WithArg("name", "user1"),
).
AssertWant(t, autogold.Want("getNameStatus n", nil))
})
t.Run("Admin should be able to register without paying FUSD", func(t *testing.T) {
otu.O.Tx("adminRegisterName",
WithSigner("find-admin"),
WithArg("names", `["find-admin"]`),
WithArg("user", "find"),
).
AssertSuccess(t).
AssertEvent(t, otu.identifier("FIND", "Register"), map[string]interface{}{
"name": "find-admin",
})
})
t.Run("Should get expected output for renew name script", func(t *testing.T) {
otu.O.Script("getMetadataForRenewNameDapper",
WithArg("merchAccount", "find"),
WithArg("name", "user1"),
WithArg("amount", 5.0),
).AssertWant(t, autogold.Want("getMetadataForRenewNameDapper", map[string]interface{}{
"amount": 5, "description": "Renew name :user1 for DUC 5.00000000",
"id": 0,
"imageURL": "https://ik.imagekit.io/xyvsisxky/tr:ot-user1,ots-55,otc-58B792,ox-N166,oy-N24,ott-b/https://i.imgur.com/8W8NoO1.png",
"name": "user1",
}))
})
otu.renewDapperUserWithName("user1", "user1").
createDapperUser("user2").
registerDapperUser("user2")
otu.tickClock(1.0)
t.Run("Should be able to send lease to another name", func(t *testing.T) {
otu.O.Tx("moveNameToDapper",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("receiver", "user2"),
).
AssertSuccess(t).
AssertEvent(t, otu.identifier("FIND", "Moved"), map[string]interface{}{
"name": "user1",
})
})
t.Run("Should automatically set Find name to empty if sender have none", func(t *testing.T) {
otu.O.Script("getName",
WithArg("address", "user1"),
).
AssertWant(t, autogold.Want("getName empty", nil))
otu.moveNameTo("user2", "user1", "user1")
})
t.Run("Should automatically set Find Name if sender have one", func(t *testing.T) {
otu.registerDapperUserWithName("user1", "name1").
moveNameTo("user1", "user2", "user1")
otu.O.Script("getName",
WithArg("address", "user1"),
).
AssertWant(t, autogold.Want("getName empty", "name1"))
otu.moveNameTo("user2", "user1", "user1")
})
otu.setProfile("user2")
t.Run("Should be able to register related account and remove it", func(t *testing.T) {
otu.O.Tx("setRelatedAccountDapper",
WithSigner("user1"),
WithArg("name", "dapper"),
WithArg("target", "user2"),
).
AssertSuccess(t).
AssertEvent(t, otu.identifier("FindRelatedAccounts", "RelatedAccount"), map[string]interface{}{
"walletName": "dapper",
"user": otu.O.Address("user1"),
"address": otu.O.Address("user2"),
"action": "add",
})
otu.O.Script("getFindStatus",
WithArg("user", "user1"),
).
AssertWithPointerWant(t, "/accounts/0",
autogold.Want("getFindStatus Dapper", map[string]interface{}{
"address": otu.O.Address("user2"),
"name": "dapper",
"network": "Flow",
"node": "FindRelatedAccounts",
"trusted": false,
}))
otu.O.Tx("removeRelatedAccountDapper",
WithSigner("user1"),
WithArg("name", "dapper"),
WithArg("network", "Flow"),
WithArg("address", otu.O.Address("user2")),
).
AssertSuccess(t).
AssertEvent(t, otu.identifier("FindRelatedAccounts", "RelatedAccount"), map[string]interface{}{
"walletName": "dapper",
"user": otu.O.Address("user1"),
"address": otu.O.Address("user2"),
"action": "remove",
"network": "Flow",
})
otu.O.Script("getFindStatus",
WithArg("user", "user1"),
).
AssertWithPointerError(t, "/accounts",
"Object has no key 'accounts'")
})
t.Run("Should be able to set private mode", func(t *testing.T) {
otu.O.Tx("setPrivateModeDapper",
WithSigner("user1"),
WithArg("mode", true),
).AssertSuccess(t)
otu.O.Script("getFindStatus",
WithArg("user", "user1"),
).
AssertWithPointerWant(t, "/privateMode",
autogold.Want("privatemode true", true),
)
otu.O.Tx("setPrivateModeDapper",
WithSigner("user1"),
WithArg("mode", false),
).AssertSuccess(t)
otu.O.Script("getFindStatus",
WithArg("user", "user1"),
).
AssertWithPointerWant(t, "/privateMode",
autogold.Want("privatemode false", false),
)
})
t.Run("Should be able to getFindStatus of new user", func(t *testing.T) {
nameAddress := otu.O.Address("user3")
otu.O.Script("getFindStatus",
WithArg("user", nameAddress),
).AssertWant(t,
autogold.Want("getFindStatus", map[string]interface{}{
"activatedAccount": true, "hasLostAndFoundItem": false,
"isDapper": false,
"isReadyForNameOffer": false,
"privateMode": false,
"readyForWearables": false,
}),
)
})
t.Run("Should be able to getFindPaths of a user", func(t *testing.T) {
nameAddress := otu.O.Address("user1")
otu.O.Script("getFindPaths",
WithArg("user", nameAddress),
).AssertWant(t,
autogold.Want("getFindPaths", map[string]interface{}{"address": "0xf669cb8d41ce0c74", "paths": []interface{}{
"findDandy",
"A_179b6b1cb6755e31_FindMarketDirectOfferSoft_SaleItemCollection_find",
"A_179b6b1cb6755e31_FindLeaseMarketDirectOfferSoft_SaleItemCollection_find",
"dapperUtilityCoinVault",
}}),
)
})
t.Run("If a user holds an invalid find name, get status should not return it", func(t *testing.T) {
nameAddress := otu.O.Address("user2")
otu.moveNameTo("user2", "user1", "user2")
otu.O.Script("getFindStatus",
WithArg("user", nameAddress),
).AssertWithPointerError(t,
"/profile/findName",
"Object has no key 'findName'",
)
})
t.Run("Should be able to create and edit the social link", func(t *testing.T) {
otu.O.Tx("editProfileDapper",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("description", "This is description"),
WithArg("avatar", "This is avatar"),
WithArg("tags", `["This is tag"]`),
WithArg("allowStoringFollowers", true),
WithArg("linkTitles", map[string]string{"CryptoTwitter": "0xBjartek", "FindTwitter": "find"}),
WithArg("linkTypes", map[string]string{"CryptoTwitter": "Twitter", "FindTwitter": "Twitter"}),
WithArg("linkUrls", map[string]string{"CryptoTwitter": "https://twitter.com/0xBjartek", "FindTwitter": "https://twitter.com/findonflow"}),
WithArg("removeLinks", "[]"),
).
AssertSuccess(t)
otu.O.Script("getFindStatus",
WithArg("user", "user1"),
).AssertWithPointerWant(t,
"/profile/links/FindTwitter",
autogold.Want("getFindStatus Find twitter", map[string]interface{}{
"title": "find",
"type": "Twitter",
"url": "https://twitter.com/findonflow",
}),
)
otu.O.Tx("editProfileDapper",
WithSigner("user1"),
WithArg("name", "user1"),
WithArg("description", "This is description"),
WithArg("avatar", "This is avatar"),
WithArg("tags", `["This is tag"]`),
WithArg("allowStoringFollowers", true),
WithArg("linkTitles", "{}"),
WithArg("linkTypes", "{}"),
WithArg("linkUrls", "{}"),
WithArg("removeLinks", `["FindTwitter"]`),
).
AssertSuccess(t)
otu.O.Script("getFindStatus",
WithArg("user", "user1"),
).AssertWithPointerError(t,
"/profile/links/FindTwitter",
"Object has no key 'FindTwitter'",
)
})
t.Run("Should get expected output for buyAddon script", func(t *testing.T) {
otu.O.Script("getMetadataForBuyAddonDapper",
WithArg("merchAccount", "find"),
WithArg("name", "name1"),
WithArg("addon", "forge"),
WithArg("amount", 10.0),
).AssertWant(t, autogold.Want("getMetadataForBuyAddonDapper", map[string]interface{}{
"amount": 10, "description": "Purchase addon forge for name :name1 for DUC 10.00000000",
"id": 0,
"imageURL": "https://i.imgur.com/8W8NoO1.png",
"name": "name1",
}))
})
t.Run("Should be able to buy addons that are on Network", func(t *testing.T) {
user := "user1"
otu.buyForgeDapper(user)
/* Should not be able to buy addons with wrong balance */
otu.O.Tx("buyAddonDapper",
WithSigner("user1"),
WithPayloadSigner("dapper"),
WithArg("merchAccount", "dapper"),
WithArg("name", "name1"),
WithArg("addon", "forge"),
WithArg("amount", 10.0),
).
AssertFailure(t, "Expect 50.00000000 Dapper Credit for forge addon")
/* Should not be able to buy addons that does not exist */
otu.O.Tx("buyAddonDapper",
WithSigner(user),
WithPayloadSigner("dapper"),
WithArg("merchAccount", "dapper"),
WithArg("name", user),
WithArg("addon", dandyNFTType(otu)),
WithArg("amount", 10.0),
).
AssertFailure(t, "This addon is not available.")
})
}