difftreelog
tests: use new contracts api
in: master
1 file changed
tests/src/util/contracthelpers.tsdiffbeforeafterboth20const gasLimit = '200000000000';20const gasLimit = '200000000000';21const endowment = '100000000000000000';21const endowment = '100000000000000000';222223function 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 code26 .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 blueprint30 resolve(result.blueprint);31 unsub();32 }33 })34 });35}3637function 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;4041 const unsub = await blueprint.tx25 const unsub = await code42 .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 blueprint45 unsub();30 resolve((result as any).contract);46 resolve(result);31 unsub();47 }32 }48 }); 33 })49 });34 });50}35}5136745975 const code = new CodePromise(api, abi, wasm);60 const code = new CodePromise(api, abi, wasm);766177 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;796380 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;128112129 const code = new CodePromise(api, abi, wasm);113 const code = new CodePromise(api, abi, wasm);130114131 const blueprint = await deployBlueprint(deployer, code);115 const contract = await deployContract(deployer, code);132 const contract = (await instantiateTransferContract(deployer, blueprint))['contract'] as Contract;133116134 return [contract, deployer];117 return [contract, deployer];135}118}