git.delta.rocks / unique-network / refs/commits / 16ee61f3b724

difftreelog

test evm payable

Yaroslav Bolyukin2021-08-23parent: #d614bc7.patch.diff
in: master

3 files changed

addedtests/src/eth/payable.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -197,16 +197,27 @@
   return flipper;
 }
 
-export async function deployCollector(web3: Web3 & Web3HttpMarker, deployer: string) {
+export async function deployCollector(web3: Web3, deployer: string) {
   const compiled = compileContract('Collector', `
     contract Collector {
       uint256 collected;
+      fallback() external payable {
+        giveMoney();
+      }
       function giveMoney() public payable {
         collected += msg.value;
       }
       function getCollected() public view returns (uint256) {
         return collected;
       }
+      function getUnaccounted() public view returns (uint256) {
+        return address(this).balance - collected;
+      }
+
+      function withdraw(address payable target) public {
+        target.transfer(collected);
+        collected = 0;
+      }
     }
   `);
   const Collector = new web3.eth.Contract(compiled.abi, undefined, {
modifiedtests/src/substrate/get-balance.tsdiffbeforeafterboth
--- a/tests/src/substrate/get-balance.ts
+++ b/tests/src/substrate/get-balance.ts
@@ -6,9 +6,24 @@
 import { ApiPromise } from '@polkadot/api';
 import {AccountInfo} from '@polkadot/types/interfaces/system';
 import promisifySubstrate from './promisify-substrate';
+import { IKeyringPair } from '@polkadot/types/types';
+import { submitTransactionAsync } from './substrate-api';
+import { getGenericResult } from '../util/helpers';
+import { expect } from 'chai';
 
 export default async function getBalance(api: ApiPromise, accounts: string[]): Promise<Array<bigint>> {
   const balance = promisifySubstrate(api, (acc: string[]) => api.query.system.account.multi(acc));
   const responce = await balance(accounts) as unknown as AccountInfo[];
   return responce.map((r) => r.data.free.toBigInt().valueOf());
 }
+
+export async function getBalanceSingle(api: ApiPromise, account: string): Promise<bigint> {
+  return (await getBalance(api, [account]))[0];
+}
+
+export async function transferBalanceExpectSuccess(api: ApiPromise, from: IKeyringPair, to: string, amount: bigint | string) {
+  const tx = api.tx.balances.transfer(to, amount);
+  const events = await submitTransactionAsync(from, tx);
+  const result = getGenericResult(events);
+  expect(result.success).to.be.true;
+}
\ No newline at end of file