1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';1819import {itEth, expect, usingEthPlaygrounds, EthUniqueHelper} from './util/playgrounds';2021describe('EVM payable contracts', () => {22 let donor: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (_, privateKey) => {26 donor = privateKey('//Alice');27 });28 });2930 itEth('Update proxy contract', async({helper}) => {31 const deployer = await helper.eth.createAccountWithBalance(donor);32 const proxyContract = await deployProxyContract(helper, deployer);33 const realContractV1 = await deployRealContractV1(helper, deployer);34 await proxyContract.methods.updateVersion(realContractV1.options.address).send();35 await proxyContract.methods.flip().send();36 await proxyContract.methods.flip().send();37 await proxyContract.methods.flip().send();38 const value1 = await proxyContract.methods.getValue().call();39 const flipCount1 = await proxyContract.methods.getFlipCount().call();40 expect(value1).to.be.equal(true);41 expect(flipCount1).to.be.equal('3');42 const realContractV2 = await deployRealContractV2(helper, deployer);43 await proxyContract.methods.updateVersion(realContractV2.options.address).send();44 await proxyContract.methods.flip().send();45 await proxyContract.methods.flip().send();46 const value2 = await proxyContract.methods.getValue().call();47 const flipCount2 = await proxyContract.methods.getFlipCount().call();48 expect(value2).to.be.equal(true);49 expect(flipCount2).to.be.equal('1');50 });5152 async function deployProxyContract(helper: EthUniqueHelper, deployer: string) {53 return await helper.ethContract.deployByCode(deployer, 'ProxyContract', `54 // SPDX-License-Identifier: UNLICENSED55 pragma solidity ^0.8.6;56 57 contract ProxyContract {58 address realContract;59 event NewEvent(uint data);60 receive() external payable {}61 constructor() {}62 function updateVersion(address newContractAddress) external {63 realContract = newContractAddress;64 }65 function flip() external {66 RealContract(realContract).flip();67 }68 function getValue() external view returns (bool) {69 return RealContract(realContract).getValue();70 }71 function getFlipCount() external view returns (uint) {72 return RealContract(realContract).getFlipCount();73 }74 }75 76 interface RealContract {77 function flip() external;78 function getValue() external view returns (bool);79 function getFlipCount() external view returns (uint);80 }`);81 }8283 async function deployRealContractV1(helper: EthUniqueHelper, deployer: string) {84 return await helper.ethContract.deployByCode(deployer, 'RealContractV1', `85 // SPDX-License-Identifier: UNLICENSED86 pragma solidity ^0.8.6;87 88 contract RealContractV1 {89 bool value = false;90 uint flipCount = 0;91 function flip() external {92 value = !value;93 flipCount++;94 }95 function getValue() external view returns (bool) {96 return value;97 }98 function getFlipCount() external view returns (uint) {99 return flipCount;100 }101 }`);102 }103104 async function deployRealContractV2(helper: EthUniqueHelper, deployer: string) {105 return await helper.ethContract.deployByCode(deployer, 'RealContractV2', `106 // SPDX-License-Identifier: UNLICENSED107 pragma solidity ^0.8.6;108 109 contract RealContractV2 {110 bool value = false;111 uint flipCount = 10;112 function flip() external {113 value = !value;114 flipCount--;115 }116 function getValue() external view returns (bool) {117 return value;118 }119 function getFlipCount() external view returns (uint) {120 return flipCount;121 }122 }`);123 }124});