difftreelog
fix replace old helpers with new ones
in: master
2 files changed
tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth--- a/tests/src/eth/marketplace/marketplace.test.ts
+++ b/tests/src/eth/marketplace/marketplace.test.ts
@@ -17,14 +17,10 @@
import {usingPlaygrounds} from './../../util/playgrounds/index';
import {IKeyringPair} from '@polkadot/types/types';
import {readFile} from 'fs/promises';
-import {collectionIdToAddress, contractHelpers, GAS_ARGS, SponsoringMode} from '../util/helpers';
-import nonFungibleAbi from '../nonFungibleAbi.json';
-
-import {itEth, expect} from '../util/playgrounds';
-
-const PRICE = 2000n;
+import {itEth, expect, SponsoringMode} from '../util/playgrounds';
describe('Matcher contract usage', () => {
+ const PRICE = 2000n;
let donor: IKeyringPair;
let alice: IKeyringPair;
let aliceMirror: string;
@@ -55,12 +51,12 @@
const matcherOwner = await helper.eth.createAccountWithBalance(donor);
const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
from: matcherOwner,
- ...GAS_ARGS,
+ gas: helper.eth.DEFAULT_GAS,
});
const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});
const sponsor = await helper.eth.createAccountWithBalance(donor);
- const helpers = contractHelpers(web3, matcherOwner);
+ const helpers = helper.ethNativeContract.contractHelpers(matcherOwner);
await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner});
await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});
@@ -70,7 +66,7 @@
const collection = await helper.nft.mintCollection(alice, {limits: {sponsorApproveTimeout: 1}, pendingSponsor: alice.address});
await collection.confirmSponsorship(alice);
await collection.addToAllowList(alice, {Substrate: aliceDoubleMirror});
- const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection.collectionId), {from: matcherOwner});
+ const evmCollection = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
await helper.eth.transferBalanceFromSubstrate(donor, aliceMirror);
await helpers.methods.toggleAllowed(matcher.options.address, aliceMirror, true).send({from: matcherOwner});
@@ -112,14 +108,14 @@
const matcherOwner = await helper.eth.createAccountWithBalance(donor);
const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
from: matcherOwner,
- ...GAS_ARGS,
+ gas: helper.eth.DEFAULT_GAS,
});
const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner, gas: 10000000});
const sponsor = await helper.eth.createAccountWithBalance(donor);
const escrow = await helper.eth.createAccountWithBalance(donor);
await matcher.methods.setEscrow(escrow).send({from: matcherOwner});
- const helpers = contractHelpers(web3, matcherOwner);
+ const helpers = helper.ethNativeContract.contractHelpers(matcherOwner);
await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner});
await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});
@@ -129,7 +125,7 @@
const collection = await helper.nft.mintCollection(alice, {limits: {sponsorApproveTimeout: 1}, pendingSponsor: alice.address});
await collection.confirmSponsorship(alice);
await collection.addToAllowList(alice, {Substrate: aliceDoubleMirror});
- const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection.collectionId), {from: matcherOwner});
+ const evmCollection = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
await helper.eth.transferBalanceFromSubstrate(donor, aliceMirror);
@@ -181,14 +177,14 @@
const matcherOwner = await helper.eth.createAccountWithBalance(donor);
const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
from: matcherOwner,
- ...GAS_ARGS,
+ gas: helper.eth.DEFAULT_GAS,
});
const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});
await helper.eth.transferBalanceFromSubstrate(donor, matcher.options.address);
const collection = await helper.nft.mintCollection(alice, {limits: {sponsorApproveTimeout: 1}});
- const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection.collectionId), {from: matcherOwner});
+ const evmCollection = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');
await helper.balance.transferToSubstrate(donor, seller.address, 100_000_000_000_000_000_000n);
tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56import config from '../../../config';78import {EthUniqueHelper} from './unique.dev';9import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';1011export {EthUniqueHelper} from './unique.dev';1213import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15import chaiLike from 'chai-like';16import {requirePalletsOrSkip} from '../../../util/playgrounds';17chai.use(chaiAsPromised);18chai.use(chaiLike);19export const expect = chai.expect;2021export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {22 const silentConsole = new SilentConsole();23 silentConsole.enable();2425 const helper = new EthUniqueHelper(new SilentLogger());2627 try {28 await helper.connect(config.substrateUrl);29 await helper.connectWeb3(config.substrateUrl);30 const ss58Format = helper.chain.getChainProperties().ss58Format;31 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);32 await code(helper, privateKey);33 }34 finally {35 await helper.disconnect();36 await helper.disconnectWeb3();37 silentConsole.disable();38 }39};40 41export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {42 (opts.only ? it.only : 43 opts.skip ? it.skip : it)(name, async function() {44 await usingEthPlaygrounds(async (helper, privateKey) => {45 if (opts.requiredPallets) {46 requirePalletsOrSkip(this, helper, opts.requiredPallets);47 }4849 await cb({helper, privateKey});50 });51 });52}5354export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {55 return itEth(name, cb, {requiredPallets: required, ...opts});56}5758itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});59itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});6061itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {only: true});62itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});63itEth.ifWithPallets = itEthIfWithPallet;1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56import config from '../../../config';78import {EthUniqueHelper} from './unique.dev';9import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';1011export {EthUniqueHelper} from './unique.dev';1213import chai from 'chai';14import chaiAsPromised from 'chai-as-promised';15import chaiLike from 'chai-like';16import {requirePalletsOrSkip} from '../../../util/playgrounds';17chai.use(chaiAsPromised);18chai.use(chaiLike);19export const expect = chai.expect;2021export enum SponsoringMode {22 Disabled = 0,23 Allowlisted = 1,24 Generous = 2,25}2627export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {28 const silentConsole = new SilentConsole();29 silentConsole.enable();3031 const helper = new EthUniqueHelper(new SilentLogger());3233 try {34 await helper.connect(config.substrateUrl);35 await helper.connectWeb3(config.substrateUrl);36 const ss58Format = helper.chain.getChainProperties().ss58Format;37 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);38 await code(helper, privateKey);39 }40 finally {41 await helper.disconnect();42 await helper.disconnectWeb3();43 silentConsole.disable();44 }45};46 47export async function itEth(name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {48 (opts.only ? it.only : 49 opts.skip ? it.skip : it)(name, async function() {50 await usingEthPlaygrounds(async (helper, privateKey) => {51 if (opts.requiredPallets) {52 requirePalletsOrSkip(this, helper, opts.requiredPallets);53 }5455 await cb({helper, privateKey});56 });57 });58}5960export async function itEthIfWithPallet(name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean, requiredPallets?: string[] } = {}) {61 return itEth(name, cb, {requiredPallets: required, ...opts});62}6364itEth.only = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {only: true});65itEth.skip = (name: string, cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEth(name, cb, {skip: true});6667itEthIfWithPallet.only = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {only: true});68itEthIfWithPallet.skip = (name: string, required: string[], cb: (apis: { helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair }) => any) => itEthIfWithPallet(name, required, cb, {skip: true});69itEth.ifWithPallets = itEthIfWithPallet;