-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmetadata.test.ts
76 lines (67 loc) · 3.33 KB
/
metadata.test.ts
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
import test, {Assertions} from "ava";
import {aliceActor, bobActor, custodianActor, custodianIdentity, johnActor} from "../setup";
const normalActors = [aliceActor, bobActor, johnActor];
const allActors = [...normalActors, custodianActor];
test("CRUD name", async (t: Assertions) => {
(await Promise.all(allActors.map(actor => actor.dip721_name()))).forEach(result => t.deepEqual(result, []));
await t.notThrowsAsync(custodianActor.dip721_set_name("nft"));
(await Promise.all(allActors.map(actor => actor.dip721_name()))).forEach(result => t.deepEqual(result, ["nft"]));
});
test("CRUD logo", async (t: Assertions) => {
(await Promise.all(allActors.map(actor => actor.dip721_logo()))).forEach(result => t.deepEqual(result, []));
await t.notThrowsAsync(custodianActor.dip721_set_logo("nftLogo"));
(await Promise.all(allActors.map(actor => actor.dip721_logo()))).forEach(result => t.deepEqual(result, ["nftLogo"]));
});
test("CRUD symbol", async (t: Assertions) => {
(await Promise.all(allActors.map(actor => actor.dip721_symbol()))).forEach(result => t.deepEqual(result, []));
await t.notThrowsAsync(custodianActor.dip721_set_symbol("nftSymbol"));
(await Promise.all(allActors.map(actor => actor.dip721_symbol()))).forEach(result =>
t.deepEqual(result, ["nftSymbol"])
);
});
test("CRUD custodians", async (t: Assertions) => {
(await Promise.all(allActors.map(actor => actor.dip721_custodians()))).forEach(result =>
t.is(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
result.filter((custodians: any) => custodians.toText() === custodianIdentity.getPrincipal().toText()).length,
1
)
);
await t.notThrowsAsync(
custodianActor.dip721_set_custodians([custodianIdentity.getPrincipal(), custodianIdentity.getPrincipal()])
);
(await Promise.all(allActors.map(actor => actor.dip721_custodians()))).forEach(result =>
t.deepEqual(result, [custodianIdentity.getPrincipal()])
);
});
test("interfaces", async (t: Assertions) => {
(await Promise.all(allActors.map(actor => actor.dip721_supported_interfaces()))).forEach(result => {
t.deepEqual(result, [{Approval: null}, {Mint: null}, {Burn: null}]);
});
});
test("metadata", async t => {
(await Promise.all(allActors.map(actor => actor.dip721_metadata()))).forEach(result => {
t.deepEqual(result.name, ["nft"]);
t.deepEqual(result.logo, ["nftLogo"]);
t.deepEqual(result.symbol, ["nftSymbol"]);
t.deepEqual(result.custodians, [custodianIdentity.getPrincipal()]);
});
});
test("error on unauthorized metadata update", async t => {
// setName error when caller is not an custodian
(await Promise.allSettled(normalActors.map(actor => actor.dip721_set_name("nft")))).forEach(promise =>
t.is(promise.status, "rejected")
);
// setLogo error when caller is not an custodian
(await Promise.allSettled(normalActors.map(actor => actor.dip721_set_logo("nftLogo")))).forEach(promise =>
t.is(promise.status, "rejected")
);
// setSymbol error when caller is not an custodian
(await Promise.allSettled(normalActors.map(actor => actor.dip721_set_symbol("nftSymbol")))).forEach(promise =>
t.is(promise.status, "rejected")
);
// setCustodians error when caller is not an custodian
(await Promise.allSettled(normalActors.map(actor => actor.dip721_set_custodians([])))).forEach(promise =>
t.is(promise.status, "rejected")
);
});