1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {itEth, usingEthPlaygrounds} from './util/index.js';19import {expect} from 'chai';2021describe('Send value to contract', () => {22 let donor: IKeyringPair;2324 before(async () => {25 await usingEthPlaygrounds(async (_helper, privateKey) => {26 donor = await privateKey({url: import.meta.url});27 });28 });2930 itEth('Send to and from contract', async ({helper}) => {31 const contractOwner = await helper.eth.createAccountWithBalance(donor, 600n);32 const [buyer, receiver] = await helper.arrange.createAccounts([600n, 600n], donor);33 const receiverMirror = helper.address.substrateToEth(receiver.address);34 const contract = await helper.ethContract.deployByCode(35 contractOwner,36 'Test',37 `38 // SPDX-License-Identifier: UNLICENSED39 pragma solidity ^0.8.18;40 41 contract Test {42 function send() public payable {43 if (msg.value < 1000000000000000000)44 revert("Not enough gold");45 }46 47 function withdraw(address to) public {48 payable(to).transfer(1000000000000000000);49 }50 }51 `,52 );5354 const balanceBefore = await helper.balance.getSubstrate(buyer.address);55 await helper.eth.sendEVM(buyer, contract.options.address, contract.methods.send().encodeABI(), '2000000000000000000');56 const balanceAfter = await helper.balance.getSubstrate(buyer.address);57 expect(balanceBefore - balanceAfter > 2000000000000000000n).to.be.true;58 expect(await helper.balance.getEthereum(contract.options.address)).to.be.equal(2000000000000000000n);5960 await helper.eth.sendEVM(buyer, contract.options.address, contract.methods.withdraw(receiverMirror).encodeABI(), '0');61 expect(await helper.balance.getEthereum(receiverMirror)).to.be.equal(1000000000000000000n);62 expect(await helper.balance.getEthereum(contract.options.address)).to.be.equal(1000000000000000000n);63 });64});