-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathcreate_contract.spec.ts
58 lines (40 loc) · 2.12 KB
/
create_contract.spec.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
import expect from 'expect';
import { weight, createConnection, deploy, transaction, aliceKeypair, query, debug_buffer, dry_run, } from './index';
import { ContractPromise } from '@polkadot/api-contract';
import { ApiPromise } from '@polkadot/api';
describe('Deploy create_contract contract and test', () => {
let conn: ApiPromise;
before(async function () {
conn = await createConnection();
});
after(async function () {
await conn.disconnect();
});
it('create_contract', async function () {
this.timeout(50000);
const alice = aliceKeypair();
// call the constructors
let deploy_contract = await deploy(conn, alice, 'creator.contract', BigInt(1e16));
// we need to have upload the child code
let _ = await deploy(conn, alice, 'child_create_contract.contract', BigInt(0));
let contract = new ContractPromise(conn, deploy_contract.abi, deploy_contract.address);
let dry = await dry_run(conn, contract, "createChild");
// Expect the instantiation nonce to be present
const current_nonce = dry.debugMessage.split('\n')[0].split('=');
expect(current_nonce[0]).toEqual("call: instantiation_nonce");
const gasLimit = dry.gasRequired;
let tx = contract.tx.createChild({ gasLimit });
await transaction(tx, alice);
let res2 = await query(conn, alice, contract, "callChild");
expect(res2.output?.toJSON()).toStrictEqual("child");
// child was created with a balance of 1e15, verify
res2 = await query(conn, alice, contract, "c");
let child = res2.output!.toString();
let { data: { free: childBalance } } = await conn.query.system.account(child);
expect(BigInt(1e15) - childBalance.toBigInt()).toBeLessThan(1e11);
// Expect the instantiation nonce to be present and to increase
const next_nonce = (await debug_buffer(conn, contract, "createChild")).split('\n')[0].split('=');
expect(next_nonce[0]).toEqual("call: instantiation_nonce");
expect(parseInt(current_nonce[1])).toBeLessThan(parseInt(next_nonce[1]));
});
});