-
Notifications
You must be signed in to change notification settings - Fork 33
/
nft.ava.ts
66 lines (61 loc) · 1.75 KB
/
nft.ava.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
import { Workspace, NearAccount } from "near-workspaces-ava";
import { NEAR } from "near-units";
import {
costPerToken,
tokenStorageCost,
totalCost,
MINT_ONE_GAS,
nftTokensForOwner,
deployEmpty,
InitArgs,
binPath,
DEFAULT_SALE,
} from "./util";
const price = NEAR.parse("1 N");
// const min_cost = NEAR.parse("0.01 N");
const runner = Workspace.init(
{ initialBalance: NEAR.parse("15 N").toString() },
async ({ root }) => {
let tenk = await root.createAndDeploy("tenk", binPath("tenk"));
let args: InitArgs = {
owner_id: root.accountId,
metadata: {
name: "TENK NFT",
symbol: "TENK",
uri: "https://bafybeiehqz6vklvxkopg3un3avdtevch4cywuihgxrb4oio2qgxf4764bi.ipfs.dweb.link",
},
size: 100,
sale: DEFAULT_SALE,
};
await root.call(tenk, "new_default_meta", args);
return { tenk };
}
);
runner.test("can get cost per token", async (t, { tenk }) => {
const cost = await costPerToken(tenk, 1);
t.deepEqual(cost.toBigInt(), price.toBigInt());
});
async function assertXTokens(t, root: NearAccount, tenk, num) {
const method = num == 1 ? "nft_mint_one" : "nft_mint_many";
let args = num == 1 ? {} : { num };
const res = await root.call_raw(tenk, method, args, {
attachedDeposit: await totalCost(tenk, num),
gas: MINT_ONE_GAS,
});
t.true(res.succeeded, [res.Failure, ...res.promiseErrorMessages].join("\n"));
t.is(num, (await nftTokensForOwner(root, tenk)).length);
if (num == 30 && Workspace.networkIsTestnet()) {
await deployEmpty(tenk);
}
}
[
["one", 1],
["two", 2],
["five", 5],
["ten", 10],
// ["thirty", 30],
].forEach(async ([num, x]) => {
runner.test("mint " + num, async (t, { root, tenk }) => {
await assertXTokens(t, root, tenk, x);
});
});