-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathpremint.ava.ts
86 lines (78 loc) · 2.38 KB
/
premint.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { ONE_NEAR, Workspace } from "near-workspaces-ava";
import { NEAR } from "near-units";
import {
claim,
createLinkdrop,
deploy,
getTokens,
mint,
mint_raw,
now,
sleep,
start_presale_args,
totalCost,
} from "./util";
const presale_price = NEAR.parse("0.8 N").toJSON();
const allowance = 2;
const runner = Workspace.init(
{ initialBalance: NEAR.parse("20 N").toString() },
async ({ root }) => {
const alice = await root.createAccount("alice");
const tenk = await deploy(root, "tenk", {
sale: {
allowance,
price: ONE_NEAR.toJSON(),
presale_price,
},
});
return { tenk, alice };
}
);
async function premint_period<T>(
{ tenk, root, duration },
fn: () => Promise<T>
): Promise<T> {
const public_sale_start = now() + duration * 1_000;
const args: start_presale_args = { public_sale_start };
await root.call(tenk, "start_presale", args);
const sleepTimer = sleep(1000 * duration);
const res = await fn();
await sleepTimer;
return res;
}
runner.test("premint", async (t, { root, tenk, alice }) => {
const cost = await totalCost(tenk, 1, alice.accountId);
const token = await mint(tenk, root);
const duration = 20;
const linkkeys = await createLinkdrop(t, tenk, root);
await claim(t, tenk, alice, linkkeys);
await premint_period({ tenk, root, duration }, async () => {
// await t.throwsAsync(
// root.call(tenk, "end_premint", {
// base_cost,
// min_cost: base_cost,
// })
// );
let initial_try = await mint_raw(tenk, alice, cost);
t.assert(initial_try.failed);
// owner can still mint
const second_token = await mint_raw(tenk, root);
t.assert(second_token.succeeded);
await root.call(tenk, "add_whitelist_accounts", {
accounts: [alice],
allowance: 2,
});
await mint(tenk, alice, cost);
await mint(tenk, alice, cost);
let last_try = await mint_raw(tenk, alice, cost);
t.assert(last_try.failed);
const tokens = await getTokens(tenk, alice);
t.assert(tokens.length == 3);
});
t.log(await tenk.view("get_sale_info"));
const sale_price = await totalCost(tenk, 1, alice.accountId);
t.log(sale_price.toHuman(), cost.toHuman());
t.assert(sale_price.gt(cost), "actual sale price has increased");
t.assert((await mint_raw(tenk, alice, sale_price)).failed);
t.assert((await mint_raw(tenk, root, sale_price)).succeeded);
});