difftreelog
Merge pull request #615 from UniqueNetwork/feature/playground-helpers
in: master
Add calculateFee method to playgrounds
3 files changed
tests/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);
});
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -27,6 +27,7 @@
import refungibleAbi from '../../reFungibleAbi.json';
import refungibleTokenAbi from '../../reFungibleTokenAbi.json';
import contractHelpersAbi from './../contractHelpersAbi.json';
+import {TEthereumAccount} from '../../../util/playgrounds/types';
class EthGroupBase {
helper: EthUniqueHelper;
@@ -43,13 +44,13 @@
return {error: `File not found: ${path}`};
};
- const knownImports = {} as any;
+ const knownImports = {} as {[key: string]: string};
for(const imp of imports) {
knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();
}
return function(path: string) {
- if(knownImports.hasOwnPropertyDescriptor(path)) return {contents: knownImports[path]};
+ if(path in knownImports) return {contents: knownImports[path]};
return {error: `File not found: ${path}`};
};
}
@@ -148,7 +149,7 @@
return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));
}
- async callEVM(signer: IKeyringPair, contractAddress: string, abi: any, value: string, gasLimit?: number) {
+ async sendEVM(signer: IKeyringPair, contractAddress: string, abi: string, value: string, gasLimit?: number) {
if(!gasLimit) gasLimit = this.DEFAULT_GAS;
const web3 = this.helper.getWeb3();
const gasPrice = await web3.eth.getGasPrice();
@@ -159,6 +160,10 @@
true,
);
}
+
+ async callEVM(signer: TEthereumAccount, contractAddress: string, abi: string) {
+ return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);
+ }
async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth6import {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';910101111export 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}234246235class WaitGroup {247class WaitGroup {