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
50 await helper.eth.transferBalanceFromSubstrate(alice, helper.address.substrateToEth(alice.address), 5n);50 await helper.eth.transferBalanceFromSubstrate(alice, helper.address.substrateToEth(alice.address), 5n);
5151
5252
53 await helper.eth.callEVM(alice, contract.options.address, contract.methods.giveMoney().encodeABI(), weiCount);53 await helper.eth.sendEVM(alice, contract.options.address, contract.methods.giveMoney().encodeABI(), weiCount);
5454
55 expect(await contract.methods.getCollected().call()).to.be.equal(weiCount);55 expect(await contract.methods.getCollected().call()).to.be.equal(weiCount);
56 });56 });
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
6import {ApiPromise, WsProvider} from '@polkadot/api';6import {ApiPromise, WsProvider} from '@polkadot/api';
7import * as defs from '../../interfaces/definitions';7import * as defs from '../../interfaces/definitions';
8import {IKeyringPair} from '@polkadot/types/types';8import {IKeyringPair} from '@polkadot/types/types';
9import {ICrossAccountId} from './types';
910
1011
11export class SilentLogger {12export class SilentLogger {
231 if(block2date! - block1date! < 9000) return true;232 if(block2date! - block1date! < 9000) return true;
232 };233 };
234
235 async calculcateFee(payer: ICrossAccountId, promise: () => Promise<any>): Promise<bigint> {
236 const address = payer.Substrate ? payer.Substrate : await this.helper.address.ethToSubstrate(payer.Ethereum!);
237 let balance = await this.helper.balance.getSubstrate(address);
238
239 await promise();
240
241 balance -= await this.helper.balance.getSubstrate(address);
242
243 return balance;
244 }
233}245}
234246
235class WaitGroup {247class WaitGroup {