git.delta.rocks / unique-network / refs/commits / a66765578aa1

difftreelog

Merge pull request #615 from UniqueNetwork/feature/playground-helpers

ut-akuznetsov2022-09-29parents: #6b0c031 #62959b2.patch.diff
in: master
Add calculateFee method to playgrounds

3 files changed

modifiedtests/src/eth/payable.test.tsdiffbeforeafterboth
--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -50,7 +50,7 @@
     await helper.eth.transferBalanceFromSubstrate(alice, helper.address.substrateToEth(alice.address), 5n);
 
 
-    await helper.eth.callEVM(alice, contract.options.address, contract.methods.giveMoney().encodeABI(), weiCount);
+    await helper.eth.sendEVM(alice, contract.options.address, contract.methods.giveMoney().encodeABI(), weiCount);
 
     expect(await contract.methods.getCollected().call()).to.be.equal(weiCount);
   });
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
27import refungibleAbi from '../../reFungibleAbi.json';27import refungibleAbi from '../../reFungibleAbi.json';
28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';
29import contractHelpersAbi from './../contractHelpersAbi.json';29import contractHelpersAbi from './../contractHelpersAbi.json';
30import {TEthereumAccount} from '../../../util/playgrounds/types';
3031
31class EthGroupBase {32class EthGroupBase {
32 helper: EthUniqueHelper;33 helper: EthUniqueHelper;
43 return {error: `File not found: ${path}`};44 return {error: `File not found: ${path}`};
44 };45 };
45 46
46 const knownImports = {} as any;47 const knownImports = {} as {[key: string]: string};
47 for(const imp of imports) {48 for(const imp of imports) {
48 knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();49 knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();
49 }50 }
50 51
51 return function(path: string) {52 return function(path: string) {
52 if(knownImports.hasOwnPropertyDescriptor(path)) return {contents: knownImports[path]};53 if(path in knownImports) return {contents: knownImports[path]};
53 return {error: `File not found: ${path}`};54 return {error: `File not found: ${path}`};
54 };55 };
55 }56 }
148 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));149 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));
149 }150 }
150151
151 async callEVM(signer: IKeyringPair, contractAddress: string, abi: any, value: string, gasLimit?: number) {152 async sendEVM(signer: IKeyringPair, contractAddress: string, abi: string, value: string, gasLimit?: number) {
152 if(!gasLimit) gasLimit = this.DEFAULT_GAS;153 if(!gasLimit) gasLimit = this.DEFAULT_GAS;
153 const web3 = this.helper.getWeb3();154 const web3 = this.helper.getWeb3();
154 const gasPrice = await web3.eth.getGasPrice();155 const gasPrice = await web3.eth.getGasPrice();
160 );161 );
161 }162 }
163
164 async callEVM(signer: TEthereumAccount, contractAddress: string, abi: string) {
165 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);
166 }
162167
163 async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {168 async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
164 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);169 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -6,6 +6,7 @@
 import {ApiPromise, WsProvider} from '@polkadot/api';
 import * as defs from '../../interfaces/definitions';
 import {IKeyringPair} from '@polkadot/types/types';
+import {ICrossAccountId} from './types';
 
 
 export class SilentLogger {
@@ -230,6 +231,17 @@
     const block2date = await findCreationDate(block2);
     if(block2date! - block1date! < 9000) return true;
   };
+  
+  async calculcateFee(payer: ICrossAccountId, promise: () => Promise<any>): Promise<bigint> {
+    const address = payer.Substrate ? payer.Substrate : await this.helper.address.ethToSubstrate(payer.Ethereum!);
+    let balance = await this.helper.balance.getSubstrate(address); 
+    
+    await promise();
+    
+    balance -= await this.helper.balance.getSubstrate(address);
+    
+    return balance;
+  }
 }
 
 class WaitGroup {