git.delta.rocks / unique-network / refs/commits / 7a3c20600074

difftreelog

tests: use new contracts api

Yaroslav Bolyukin2021-03-04parent: #17a564c.patch.diff
in: master

1 file changed

modifiedtests/src/util/contracthelpers.tsdiffbeforeafterboth
20const gasLimit = '200000000000';20const gasLimit = '200000000000';
21const endowment = '100000000000000000';21const endowment = '100000000000000000';
2222
23function deployBlueprint(alice: IKeyringPair, code: CodePromise): Promise<Blueprint> {23function deployContract(alice: IKeyringPair, code: CodePromise, constructor: string = 'default', ...args: any[]): Promise<Contract> {
24 return new Promise<Blueprint>(async (resolve, reject) => {
25 const unsub = await code
26 .createBlueprint()
27 .signAndSend(alice, (result) => {
28 if (result.status.isInBlock || result.status.isFinalized) {
29 // here we have an additional field in the result, containing the blueprint
30 resolve(result.blueprint);
31 unsub();
32 }
33 })
34 });
35}
36
37function deployContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {
38 return new Promise<any>(async (resolve, reject) => {24 return new Promise<Contract>(async (resolve, reject) => {
39 const initValue = true;
40
41 const unsub = await blueprint.tx25 const unsub = await code
42 .new(endowment, gasLimit, initValue)26 .tx[constructor]({value: endowment, gasLimit}, ...args)
43 .signAndSend(alice, (result) => {27 .signAndSend(alice, (result) => {
44 if (result.status.isInBlock || result.status.isFinalized) {28 if (result.status.isInBlock || result.status.isFinalized) {
29 // here we have an additional field in the result, containing the blueprint
45 unsub();30 resolve((result as any).contract);
46 resolve(result);31 unsub();
47 }32 }
48 }); 33 })
49 });34 });
50}35}
5136
7459
75 const code = new CodePromise(api, abi, wasm);60 const code = new CodePromise(api, abi, wasm);
7661
77 const blueprint = await deployBlueprint(deployer, code);
78 const contract = (await deployContract(deployer, blueprint))['contract'] as Contract;62 const contract = (await deployContract(deployer, code, 'new', true)) as Contract;
7963
80 const initialGetResponse = await getFlipValue(contract, deployer);64 const initialGetResponse = await getFlipValue(contract, deployer);
81 expect(initialGetResponse).to.be.true;65 expect(initialGetResponse).to.be.true;
128112
129 const code = new CodePromise(api, abi, wasm);113 const code = new CodePromise(api, abi, wasm);
130114
131 const blueprint = await deployBlueprint(deployer, code);115 const contract = await deployContract(deployer, code);
132 const contract = (await instantiateTransferContract(deployer, blueprint))['contract'] as Contract;
133116
134 return [contract, deployer];117 return [contract, deployer];
135}118}