difftreelog
Merge pull request #629 from UniqueNetwork/feature/eth-tests-playgrnds
in: master
Feature/eth tests playgrnds
7 files changed
tests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionSponsoring.test.ts
+++ b/tests/src/eth/collectionSponsoring.test.ts
@@ -1,33 +1,45 @@
-import {addToAllowListExpectSuccess, confirmSponsorshipExpectSuccess, createCollectionExpectSuccess, enablePublicMintingExpectSuccess, getDetailedCollectionInfo, setCollectionSponsorExpectSuccess, UNIQUE} from '../util/helpers';
-import {itWeb3, createEthAccount, collectionIdToAddress, GAS_ARGS, normalizeEvents, createEthAccountWithBalance, evmCollectionHelpers, getCollectionAddressFromResult, evmCollection, ethBalanceViaSub} from './util/helpers';
-import nonFungibleAbi from './nonFungibleAbi.json';
-import {expect} from 'chai';
-import {evmToAddress} from '@polkadot/util-crypto';
+import {IKeyringPair} from '@polkadot/types/types';
+import {usingPlaygrounds} from './../util/playgrounds/index';
+import {itEth, expect} from '../eth/util/playgrounds';
describe('evm collection sponsoring', () => {
- itWeb3('sponsors mint transactions', async ({web3, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let nominal: bigint;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ nominal = helper.balance.getOneTokenNominal();
+ });
+ });
+
+ beforeEach(async () => {
+ await usingPlaygrounds(async (helper) => {
+ [alice] = await helper.arrange.createAccounts([1000n], donor);
+ });
+ });
- const collection = await createCollectionExpectSuccess();
- await setCollectionSponsorExpectSuccess(collection, alice.address);
- await confirmSponsorshipExpectSuccess(collection);
+ itEth('sponsors mint transactions', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});
+ await collection.setSponsor(alice, alice.address);
+ await collection.confirmSponsorship(alice);
- const minter = createEthAccount(web3);
- expect(await web3.eth.getBalance(minter)).to.equal('0');
+ const minter = helper.eth.createAccount();
+ expect(await helper.balance.getEthereum(minter)).to.equal(0n);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);
- await enablePublicMintingExpectSuccess(alice, collection);
- await addToAllowListExpectSuccess(alice, collection, {Ethereum: minter});
+ await collection.addToAllowList(alice, {Ethereum: minter});
const nextTokenId = await contract.methods.nextTokenId().call();
expect(nextTokenId).to.equal('1');
const result = await contract.methods.mint(minter, nextTokenId).send();
- const events = normalizeEvents(result.events);
+ const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
- address,
+ address: collectionAddress,
event: 'Transfer',
args: {
from: '0x0000000000000000000000000000000000000000',
@@ -59,13 +71,14 @@
// expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);
// });
- itWeb3('Remove sponsor', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+ itEth('Remove sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
+
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
+ const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
@@ -80,30 +93,31 @@
expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');
});
- itWeb3('Sponsoring collection from evm address via access list', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+ itEth('Sponsoring collection from evm address via access list', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
+
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
+ const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
+ const collection = helper.nft.getCollectionObject(collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
+
result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
- let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
- const ss58Format = (api.registry.getChainProperties())!.toJSON().ss58Format;
- expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
- expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));
+ let collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
- collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
- expect(collectionSub.sponsorship.isConfirmed).to.be.true;
- expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));
+ collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
- const user = createEthAccount(web3);
+ const user = helper.eth.createAccount();
const nextTokenId = await collectionEvm.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
- const oldPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
+ const oldPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
expect(oldPermissions.mintMode).to.be.false;
expect(oldPermissions.access).to.be.equal('Normal');
@@ -111,12 +125,12 @@
await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
- const newPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
+ const newPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
expect(newPermissions.mintMode).to.be.true;
expect(newPermissions.access).to.be.equal('AllowList');
- const ownerBalanceBefore = await ethBalanceViaSub(api, owner);
- const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
{
const nextTokenId = await collectionEvm.methods.nextTokenId().call();
@@ -126,7 +140,7 @@
nextTokenId,
'Test URI',
).send({from: user});
- const events = normalizeEvents(result.events);
+ const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
@@ -140,8 +154,8 @@
},
]);
- const ownerBalanceAfter = await ethBalanceViaSub(api, owner);
- const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);
+ const ownerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);
@@ -205,33 +219,34 @@
// }
// });
- itWeb3('Check that transaction via EVM spend money from sponsor address', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collectionHelpers = evmCollectionHelpers(web3, owner);
- let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * UNIQUE)});
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+ itEth('Check that transaction via EVM spend money from sponsor address', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
+
+ let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
+ const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
+ const collection = helper.nft.getCollectionObject(collectionId);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
+
result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();
- let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
- const ss58Format = (api.registry.getChainProperties())!.toJSON().ss58Format;
- expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
- expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));
+ let collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
- const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
+
+ const sponsorCollection = helper.ethNativeContract.collection(collectionIdAddress, 'nft', sponsor);
await sponsorCollection.methods.confirmCollectionSponsorship().send();
- collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
- expect(collectionSub.sponsorship.isConfirmed).to.be.true;
- expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));
+ collectionData = (await collection.getData())!;
+ expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
- const user = createEthAccount(web3);
+ const user = helper.eth.createAccount();
await collectionEvm.methods.addCollectionAdmin(user).send();
- const ownerBalanceBefore = await ethBalanceViaSub(api, owner);
- const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
-
-
- const userCollectionEvm = evmCollection(web3, user, collectionIdAddress);
+ const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
+
+ const userCollectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', user);
const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
result = await userCollectionEvm.methods.mintWithTokenURI(
@@ -240,8 +255,8 @@
'Test URI',
).send();
- const events = normalizeEvents(result.events);
- const address = collectionIdToAddress(collectionId);
+ const events = helper.eth.normalizeEvents(result.events);
+ const address = helper.ethAddress.fromCollectionId(collectionId);
expect(events).to.be.deep.equal([
{
@@ -256,9 +271,9 @@
]);
expect(await userCollectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
- const ownerBalanceAfter = await ethBalanceViaSub(api, owner);
+ const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
- const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
});
});
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -14,45 +14,39 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+import {IKeyringPair} from '@polkadot/types/types';
import * as solc from 'solc';
-import {expect} from 'chai';
-import {expectSubstrateEventsAtBlock} from '../util/helpers';
-import Web3 from 'web3';
+import {EthUniqueHelper} from './util/playgrounds/unique.dev';
+import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from '../eth/util/playgrounds';
+import {usingPlaygrounds} from '../util/playgrounds';
+import {CompiledContract} from './util/playgrounds/types';
-import {
- contractHelpers,
- createEthAccountWithBalance,
- transferBalanceToEth,
- deployFlipper,
- itWeb3,
- SponsoringMode,
- createEthAccount,
- ethBalanceViaSub,
- normalizeEvents,
- CompiledContract,
- GAS_ARGS,
- subToEth,
-} from './util/helpers';
-import {submitTransactionAsync} from '../substrate/substrate-api';
+describe('Sponsoring EVM contracts', () => {
+ let donor: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (_helper, privateKey) => {
+ donor = privateKey('//Alice');
+ });
+ });
+
+ itEth('Self sponsored can be set by the address that deployed the contract', async ({helper, privateKey}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const flipper = await helper.eth.deployFlipper(owner);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
-describe('Sponsoring EVM contracts', () => {
- itWeb3('Self sponsored can be set by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).send()).to.be.not.rejected;
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
});
- itWeb3('Set self sponsored events', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Set self sponsored events', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const flipper = await helper.eth.deployFlipper(owner);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();
- // console.log(result);
- const ethEvents = normalizeEvents(result.events);
+ const ethEvents = helper.eth.helper.eth.normalizeEvents(result.events);
expect(ethEvents).to.be.deep.equal([
{
address: flipper.options.address,
@@ -71,62 +65,59 @@
},
},
]);
-
- await expectSubstrateEventsAtBlock(
- api,
- result.blockNumber,
- 'evmContractHelpers',
- ['ContractSponsorSet','ContractSponsorshipConfirmed'],
- );
});
- itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Self sponsored can not be set by the address that did not deployed the contract', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const notOwner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.selfSponsoredEnable(flipper.options.address).call({from: notOwner})).to.be.rejectedWith('NoPermission');
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
});
- itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsoring can be set by the address that has deployed the contract', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner})).to.be.not.rejected;
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
});
- itWeb3('Sponsoring cannot be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsoring cannot be set by the address that did not deployed the contract', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const notOwner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.setSponsoringMode(notOwner, SponsoringMode.Allowlisted).call({from: notOwner})).to.be.rejectedWith('NoPermission');
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.false;
});
- itWeb3('Sponsor can be set by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsor can be set by the address that deployed the contract', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.true;
});
- itWeb3('Set sponsor event', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Set sponsor event', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
const result = await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
- const events = normalizeEvents(result.events);
+ const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
address: flipper.options.address,
@@ -137,45 +128,41 @@
},
},
]);
-
- await expectSubstrateEventsAtBlock(
- api,
- result.blockNumber,
- 'evmContractHelpers',
- ['ContractSponsorSet'],
- );
});
- itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsor can not be set by the address that did not deployed the contract', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const notOwner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).call({from: notOwner})).to.be.rejectedWith('NoPermission');
expect(await helpers.methods.hasPendingSponsor(flipper.options.address).call()).to.be.false;
});
- itWeb3('Sponsorship can be confirmed by the address that pending as sponsor', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsorship can be confirmed by the address that pending as sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
await expect(helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor})).to.be.not.rejected;
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
});
- itWeb3('Confirm sponsorship event', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Confirm sponsorship event', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
const result = await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
- const events = normalizeEvents(result.events);
+ const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
address: flipper.options.address,
@@ -186,41 +173,37 @@
},
},
]);
+ });
- await expectSubstrateEventsAtBlock(
- api,
- result.blockNumber,
- 'evmContractHelpers',
- ['ContractSponsorshipConfirmed'],
- );
- });
+ itEth('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const notSponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
- itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.setSponsor(flipper.options.address, sponsor).send()).to.be.not.rejected;
await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPermission');
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
});
- itWeb3('Sponsorship can not be confirmed by the address that not set as sponsor', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notSponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsorship can not be confirmed by the address that not set as sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const notSponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await expect(helpers.methods.confirmSponsorship(flipper.options.address).call({from: notSponsor})).to.be.rejectedWith('NoPendingSponsor');
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
});
- itWeb3('Get self sponsored sponsor', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Get self sponsored sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
await helpers.methods.selfSponsoredEnable(flipper.options.address).send();
const result = await helpers.methods.sponsor(flipper.options.address).call();
@@ -229,11 +212,12 @@
expect(result[1]).to.be.eq('0');
});
- itWeb3('Get confirmed sponsor', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Get confirmed sponsor', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
@@ -243,11 +227,11 @@
expect(result[1]).to.be.eq('0');
});
- itWeb3('Sponsor can be removed by the address that deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsor can be removed by the address that deployed the contract', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
@@ -258,17 +242,17 @@
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
});
- itWeb3('Remove sponsor event', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Remove sponsor event', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
const result = await helpers.methods.removeSponsor(flipper.options.address).send();
- const events = normalizeEvents(result.events);
+ const events = helper.eth.normalizeEvents(result.events);
expect(events).to.be.deep.equal([
{
address: flipper.options.address,
@@ -278,21 +262,14 @@
},
},
]);
-
- await expectSubstrateEventsAtBlock(
- api,
- result.blockNumber,
- 'evmContractHelpers',
- ['ContractSponsorRemoved'],
- );
});
- itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsor can not be removed by the address that did not deployed the contract', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const notOwner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.false;
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
@@ -303,14 +280,12 @@
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
});
- itWeb3('In generous mode, non-allowlisted user transaction will be sponsored', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const flipper = await deployFlipper(web3, owner);
-
- const helpers = contractHelpers(web3, owner);
+ itEth('In generous mode, non-allowlisted user transaction will be sponsored', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
@@ -318,57 +293,52 @@
await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
- const callerBalanceBefore = await ethBalanceViaSub(api, caller);
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
+ const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from sponsor instead of caller
- const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);
- const callerBalanceAfter = await ethBalanceViaSub(api, caller);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
+ const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);
});
-
- itWeb3('In generous mode, non-allowlisted user transaction will be self sponsored', async ({api, web3, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('In generous mode, non-allowlisted user transaction will be self sponsored', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
await helpers.methods.selfSponsoredEnable(flipper.options.address).send();
await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Generous).send({from: owner});
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- await transferBalanceToEth(api, alice, flipper.options.address);
+ await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);
- const contractBalanceBefore = await ethBalanceViaSub(api, flipper.options.address);
- const callerBalanceBefore = await ethBalanceViaSub(api, caller);
+ const contractBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));
+ const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from sponsor instead of caller
- const contractBalanceAfter = await ethBalanceViaSub(api, flipper.options.address);
- const callerBalanceAfter = await ethBalanceViaSub(api, caller);
+ const contractBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(flipper.options.address));
+ const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
expect(contractBalanceAfter < contractBalanceBefore).to.be.true;
expect(callerBalanceAfter).to.be.eq(callerBalanceBefore);
});
- itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = createEthAccount(web3);
-
- const flipper = await deployFlipper(web3, owner);
+ itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should decrease (allowlisted)', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const caller = helper.eth.createAccount();
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
- const helpers = contractHelpers(web3, owner);
await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
@@ -378,51 +348,47 @@
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
- const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
expect(sponsorBalanceBefore).to.be.not.equal('0');
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from flipper instead of caller
- const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
});
- itWeb3('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({api, web3, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = createEthAccount(web3);
-
- const flipper = await deployFlipper(web3, owner);
+ itEth('Sponsoring is set, an address that has no UNQ can send a transaction and it works. Sponsor balance should not decrease (non-allowlisted)', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const caller = await helper.eth.createAccount();
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
- const helpers = contractHelpers(web3, owner);
-
await helpers.methods.setSponsoringMode(flipper.options.address, SponsoringMode.Allowlisted).send({from: owner});
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
- await transferBalanceToEth(api, alice, flipper.options.address);
+ await helper.eth.transferBalanceFromSubstrate(donor, flipper.options.address);
- const originalFlipperBalance = await web3.eth.getBalance(flipper.options.address);
+ const originalFlipperBalance = await helper.balance.getEthereum(flipper.options.address);
expect(originalFlipperBalance).to.be.not.equal('0');
await expect(flipper.methods.flip().send({from: caller})).to.be.rejectedWith(/InvalidTransaction::Payment/);
expect(await flipper.methods.getValue().call()).to.be.false;
// Balance should be taken from flipper instead of caller
- const balanceAfter = await web3.eth.getBalance(flipper.options.address);
- expect(+balanceAfter).to.be.equals(+originalFlipperBalance);
+ // FIXME the comment is wrong! What check should be here?
+ const balanceAfter = await helper.balance.getEthereum(flipper.options.address);
+ expect(balanceAfter).to.be.equals(originalFlipperBalance);
});
- itWeb3('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const flipper = await deployFlipper(web3, owner);
+ itEth('Sponsoring is set, an address that has UNQ can send a transaction and it works. User balance should not change', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
- const helpers = contractHelpers(web3, owner);
await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
@@ -432,27 +398,26 @@
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
- const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
- const callerBalanceBefore = await ethBalanceViaSub(api, caller);
+ const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
+ const callerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
- const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);
- const callerBalanceAfter = await ethBalanceViaSub(api, caller);
+ const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
+ const callerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(caller));
expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
expect(callerBalanceAfter).to.be.equals(callerBalanceBefore);
});
- itWeb3('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const originalCallerBalance = await web3.eth.getBalance(caller);
-
- const flipper = await deployFlipper(web3, owner);
-
- const helpers = contractHelpers(web3, owner);
+ itEth('Sponsoring is limited, with setContractRateLimit. The limitation is working if transactions are sent more often, the sender pays the commission.', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
+ const originalCallerBalance = await helper.balance.getEthereum(caller);
await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
@@ -462,34 +427,36 @@
await helpers.methods.setSponsor(flipper.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(flipper.options.address).send({from: sponsor});
- const originalFlipperBalance = await web3.eth.getBalance(sponsor);
+ const originalFlipperBalance = await helper.balance.getEthereum(sponsor);
expect(originalFlipperBalance).to.be.not.equal('0');
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
- expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
+ expect(await helper.balance.getEthereum(caller)).to.be.equals(originalCallerBalance);
- const newFlipperBalance = await web3.eth.getBalance(sponsor);
+ const newFlipperBalance = await helper.balance.getEthereum(sponsor);
expect(newFlipperBalance).to.be.not.equals(originalFlipperBalance);
await flipper.methods.flip().send({from: caller});
- expect(await web3.eth.getBalance(sponsor)).to.be.equal(newFlipperBalance);
- expect(await web3.eth.getBalance(caller)).to.be.not.equals(originalCallerBalance);
+ expect(await helper.balance.getEthereum(sponsor)).to.be.equal(newFlipperBalance);
+ expect(await helper.balance.getEthereum(caller)).to.be.not.equals(originalCallerBalance);
});
// TODO: Find a way to calculate default rate limit
- itWeb3('Default rate limit equals 7200', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Default rate limit equals 7200', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.sponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
});
});
describe('Sponsoring Fee Limit', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let DEFAULT_GAS: number;
- let testContract: CompiledContract;
-
function compileTestContract() {
if (!testContract) {
const input = {
@@ -537,46 +504,67 @@
return testContract;
}
- async function deployTestContract(web3: Web3, owner: string) {
+ async function deployTestContract(helper: EthUniqueHelper, owner: string) {
+ const web3 = helper.getWeb3();
const compiled = compileTestContract();
const testContract = new web3.eth.Contract(compiled.abi, undefined, {
data: compiled.object,
from: owner,
- ...GAS_ARGS,
+ gas: DEFAULT_GAS,
});
return await testContract.deploy({data: compiled.object}).send({from: owner});
}
- itWeb3('Default fee limit', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ before(async () => {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ DEFAULT_GAS = helper.eth.DEFAULT_GAS;
+ });
+ });
+
+ beforeEach(async () => {
+ await usingPlaygrounds(async (helper) => {
+ [alice] = await helper.arrange.createAccounts([1000n], donor);
+ });
+ });
+
+ let testContract: CompiledContract;
+
+
+
+ itEth('Default fee limit', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('115792089237316195423570985008687907853269984665640564039457584007913129639935');
});
- itWeb3('Set fee limit', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Set fee limit', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
await helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send();
expect(await helpers.methods.sponsoringFeeLimit(flipper.options.address).call()).to.be.equals('100');
});
- itWeb3('Negative test - set fee limit by non-owner', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const stranger = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const flipper = await deployFlipper(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ itEth('Negative test - set fee limit by non-owner', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const stranger = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
+ const flipper = await helper.eth.deployFlipper(owner);
+
await expect(helpers.methods.setSponsoringFeeLimit(flipper.options.address, 100).send({from: stranger})).to.be.rejected;
});
- itWeb3('Negative test - check that eth transactions exceeding fee limit are not executed', async ({api, web3, privateKeyWrapper}) => {
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const user = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ itEth('Negative test - check that eth transactions exceeding fee limit are not executed', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const user = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
- const testContract = await deployTestContract(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ const testContract = await deployTestContract(helper, owner);
await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});
await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});
@@ -584,24 +572,24 @@
await helpers.methods.setSponsor(testContract.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});
- const gasPrice = BigInt(await web3.eth.getGasPrice());
+ const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());
await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();
- const originalUserBalance = await web3.eth.getBalance(user);
+ const originalUserBalance = await helper.balance.getEthereum(user);
await testContract.methods.test(100).send({from: user, gas: 2_000_000});
- expect(await web3.eth.getBalance(user)).to.be.equal(originalUserBalance);
+ expect(await helper.balance.getEthereum(user)).to.be.equal(originalUserBalance);
await testContract.methods.test(100).send({from: user, gas: 2_100_000});
- expect(await web3.eth.getBalance(user)).to.not.be.equal(originalUserBalance);
+ expect(await helper.balance.getEthereum(user)).to.not.be.equal(originalUserBalance);
});
- itWeb3('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({api, web3, privateKeyWrapper}) => {
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ itEth('Negative test - check that evm.call transactions exceeding fee limit are not executed', async ({helper, privateKey}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
- const testContract = await deployTestContract(web3, owner);
- const helpers = contractHelpers(web3, owner);
+ const testContract = await deployTestContract(helper, owner);
await helpers.methods.setSponsoringMode(testContract.options.address, SponsoringMode.Generous).send({from: owner});
await helpers.methods.setSponsoringRateLimit(testContract.options.address, 0).send({from: owner});
@@ -609,43 +597,29 @@
await helpers.methods.setSponsor(testContract.options.address, sponsor).send();
await helpers.methods.confirmSponsorship(testContract.options.address).send({from: sponsor});
- const gasPrice = BigInt(await web3.eth.getGasPrice());
+ const gasPrice = BigInt(await helper.getWeb3().eth.getGasPrice());
await helpers.methods.setSponsoringFeeLimit(testContract.options.address, 2_000_000n * gasPrice).send();
- const alice = privateKeyWrapper('//Alice');
- const originalAliceBalance = (await api.query.system.account(alice.address)).data.free.toBigInt();
-
- await submitTransactionAsync(
+ const originalAliceBalance = await helper.balance.getSubstrate(alice.address);
+
+ await helper.eth.sendEVM(
alice,
- api.tx.evm.call(
- subToEth(alice.address),
- testContract.options.address,
- testContract.methods.test(100).encodeABI(),
- Uint8Array.from([]),
- 2_000_000n,
- gasPrice,
- null,
- null,
- [],
- ),
+ testContract.options.address,
+ testContract.methods.test(100).encodeABI(),
+ '0',
+ 2_000_000,
);
- expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance);
+ // expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.be.equal(originalAliceBalance);
+ expect(await helper.balance.getSubstrate(alice.address)).to.be.equal(originalAliceBalance);
- await submitTransactionAsync(
+ await helper.eth.sendEVM(
alice,
- api.tx.evm.call(
- subToEth(alice.address),
- testContract.options.address,
- testContract.methods.test(100).encodeABI(),
- Uint8Array.from([]),
- 2_100_000n,
- gasPrice,
- null,
- null,
- [],
- ),
+ testContract.options.address,
+ testContract.methods.test(100).encodeABI(),
+ '0',
+ 2_100_000,
);
- expect((await api.query.system.account(alice.address)).data.free.toBigInt()).to.not.be.equal(originalAliceBalance);
+ expect(await helper.balance.getSubstrate(alice.address)).to.not.be.equal(originalAliceBalance);
});
});
tests/src/eth/scheduling.test.tsdiffbeforeafterboth--- a/tests/src/eth/scheduling.test.ts
+++ b/tests/src/eth/scheduling.test.ts
@@ -18,7 +18,8 @@
import {createEthAccountWithBalance, deployFlipper, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';
import {scheduleExpectSuccess, waitNewBlocks, requirePallets, Pallets} from '../util/helpers';
-describe('Scheduing EVM smart contracts', () => {
+// TODO mrshiposha update this test in #581
+describe.skip('Scheduing EVM smart contracts', () => {
before(async function() {
await requirePallets(this, [Pallets.Scheduler]);
});
tests/src/eth/sponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/sponsoring.test.ts
+++ b/tests/src/eth/sponsoring.test.ts
@@ -14,20 +14,31 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {expect} from 'chai';
-import {contractHelpers, createEthAccount, createEthAccountWithBalance, deployCollector, deployFlipper, itWeb3, SponsoringMode} from './util/helpers';
+import {IKeyringPair} from '@polkadot/types/types';
+import {itEth, expect, SponsoringMode} from '../eth/util/playgrounds';
+import {usingPlaygrounds} from './../util/playgrounds/index';
describe('EVM sponsoring', () => {
- itWeb3('Fee is deducted from contract if sponsoring is enabled', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = createEthAccount(web3);
- const originalCallerBalance = await web3.eth.getBalance(caller);
- expect(originalCallerBalance).to.be.equal('0');
+ let donor: IKeyringPair;
- const flipper = await deployFlipper(web3, owner);
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ });
+ });
+
+ itEth('Fee is deducted from contract if sponsoring is enabled', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const caller = helper.eth.createAccount();
+ const originalCallerBalance = await helper.balance.getEthereum(caller);
+
+ expect(originalCallerBalance).to.be.equal(0n);
+
+ const flipper = await helper.eth.deployFlipper(owner);
+
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
- const helpers = contractHelpers(web3, owner);
await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});
await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});
@@ -39,27 +50,29 @@
await helpers.methods.setSponsoringRateLimit(flipper.options.address, 0).send({from: owner});
expect(await helpers.methods.sponsoringEnabled(flipper.options.address).call()).to.be.true;
- const originalSponsorBalance = await web3.eth.getBalance(sponsor);
- expect(originalSponsorBalance).to.be.not.equal('0');
+ const originalSponsorBalance = await helper.balance.getEthereum(sponsor);
+ expect(originalSponsorBalance).to.be.not.equal(0n);
await flipper.methods.flip().send({from: caller});
expect(await flipper.methods.getValue().call()).to.be.true;
// Balance should be taken from flipper instead of caller
- expect(await web3.eth.getBalance(caller)).to.be.equals(originalCallerBalance);
- expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance);
+ expect(await helper.balance.getEthereum(caller)).to.be.equal(originalCallerBalance);
+ expect(await helper.balance.getEthereum(sponsor)).to.be.not.equal(originalSponsorBalance);
});
- itWeb3('...but this doesn\'t applies to payable value', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const originalCallerBalance = await web3.eth.getBalance(caller);
- expect(originalCallerBalance).to.be.not.equal('0');
+ itEth('...but this doesn\'t applies to payable value', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const originalCallerBalance = await helper.balance.getEthereum(caller);
+
+ expect(originalCallerBalance).to.be.not.equal(0n);
+
+ const collector = await helper.eth.deployCollectorContract(owner);
- const collector = await deployCollector(web3, owner);
+ const helpers = helper.ethNativeContract.contractHelpers(owner);
- const helpers = contractHelpers(web3, owner);
await helpers.methods.toggleAllowlist(collector.options.address, true).send({from: owner});
await helpers.methods.toggleAllowed(collector.options.address, caller, true).send({from: owner});
@@ -71,14 +84,14 @@
await helpers.methods.setSponsor(collector.options.address, sponsor).send({from: owner});
await helpers.methods.confirmSponsorship(collector.options.address).send({from: sponsor});
- const originalSponsorBalance = await web3.eth.getBalance(sponsor);
- expect(originalSponsorBalance).to.be.not.equal('0');
+ const originalSponsorBalance = await helper.balance.getEthereum(sponsor);
+ expect(originalSponsorBalance).to.be.not.equal(0n);
await collector.methods.giveMoney().send({from: caller, value: '10000'});
// Balance will be taken from both caller (value) and from collector (fee)
- expect(await web3.eth.getBalance(caller)).to.be.equals((BigInt(originalCallerBalance) - 10000n).toString());
- expect(await web3.eth.getBalance(sponsor)).to.be.not.equals(originalSponsorBalance);
+ expect(await helper.balance.getEthereum(caller)).to.be.equals((originalCallerBalance - 10000n));
+ expect(await helper.balance.getEthereum(sponsor)).to.be.not.equals(originalSponsorBalance);
expect(await collector.methods.getCollected().call()).to.be.equal('10000');
});
});
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokenProperties.test.ts
+++ b/tests/src/eth/tokenProperties.test.ts
@@ -1,94 +1,119 @@
-import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess} from '../util/helpers';
-import {cartesian, collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';
-import nonFungibleAbi from './nonFungibleAbi.json';
-import {expect} from 'chai';
-import {executeTransaction} from '../substrate/substrate-api';
+import {IKeyringPair} from '@polkadot/types/types';
+import {usingPlaygrounds} from './../util/playgrounds/index';
+import {itEth, expect} from '../eth/util/playgrounds';
describe('EVM token properties', () => {
- itWeb3('Can be reconfigured', async({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([1000n], donor);
+ });
+ });
+
+ itEth('Can be reconfigured', async({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+
for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});
-
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
-
+ const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});
+ await collection.addAdmin(alice, {Ethereum: caller});
+
+ const address = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(address, 'nft', caller);
+
await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});
- const state = (await api.query.common.collectionPropertyPermissions(collection)).toJSON();
- expect(state).to.be.deep.equal({
- [web3.utils.toHex('testKey')]: {mutable, collectionAdmin, tokenOwner},
- });
+ const state = await collection.getPropertyPermissions();
+ expect(state).to.be.deep.equal([{
+ key: 'testKey',
+ permission: {mutable, collectionAdmin, tokenOwner},
+ }]);
}
});
- itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const token = await createItemExpectSuccess(alice, collection, 'NFT');
- await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{
- key: 'testKey',
- permission: {
- collectionAdmin: true,
- },
- }]));
+ itEth('Can be set', async({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.nft.mintCollection(alice, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: [{
+ key: 'testKey',
+ permission: {
+ collectionAdmin: true,
+ },
+ }],
+ });
+ const token = await collection.mintToken(alice);
- await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});
+ await collection.addAdmin(alice, {Ethereum: caller});
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+ const address = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(address, 'nft', caller);
- await contract.methods.setProperty(token, 'testKey', Buffer.from('testValue')).send({from: caller});
+ await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});
- const [{value}] = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toHuman()! as any;
+ const [{value}] = await token.getProperties(['testKey']);
expect(value).to.equal('testValue');
});
- itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
- const token = await createItemExpectSuccess(alice, collection, 'NFT');
- await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{
- key: 'testKey',
- permission: {
- mutable: true,
- collectionAdmin: true,
- },
- }]));
- await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));
+ itEth('Can be deleted', async({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.nft.mintCollection(alice, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: [{
+ key: 'testKey',
+ permission: {
+ mutable: true,
+ collectionAdmin: true,
+ },
+ }],
+ });
+
+ await collection.addAdmin(alice, {Ethereum: caller});
- await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});
+ const token = await collection.mintToken(alice);
+ await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+ const address = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(address, 'nft', caller);
- await contract.methods.deleteProperty(token, 'testKey').send({from: caller});
+ await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});
- const result = (await api.rpc.unique.tokenProperties(collection, token, ['testKey'])).toJSON()! as any;
+ const result = await token.getProperties(['testKey']);
expect(result.length).to.equal(0);
});
- itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
- const caller = createEthAccount(web3);
- const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});
- const token = await createItemExpectSuccess(alice, collection, 'NFT');
- await executeTransaction(api, alice, api.tx.unique.setTokenPropertyPermissions(collection, [{
- key: 'testKey',
- permission: {
- collectionAdmin: true,
- },
- }]));
- await executeTransaction(api, alice, api.tx.unique.setTokenProperties(collection, token, [{key: 'testKey', value: 'testValue'}]));
+ itEth('Can be read', async({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.nft.mintCollection(alice, {
+ tokenPrefix: 'ethp',
+ tokenPropertyPermissions: [{
+ key: 'testKey',
+ permission: {
+ collectionAdmin: true,
+ },
+ }],
+ });
+ const token = await collection.mintToken(alice);
+ await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+ const address = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(address, 'nft', caller);
- const value = await contract.methods.property(token, 'testKey').call();
- expect(value).to.equal(web3.utils.toHex('testValue'));
+ const value = await contract.methods.property(token.tokenId, 'testKey').call();
+ expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));
});
});
+
+
+type ElementOf<A> = A extends readonly (infer T)[] ? T : never;
+function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {
+ if(args.length === 0) {
+ yield internalRest as any;
+ return;
+ }
+ for(const value of args[0]) {
+ yield* cartesian([...internalRest, value], ...args.slice(1)) as any;
+ }
+}
\ No newline at end of file
tests/src/eth/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/types.ts
+++ b/tests/src/eth/util/playgrounds/types.ts
@@ -6,4 +6,10 @@
export interface CompiledContract {
abi: any;
object: string;
-}
\ No newline at end of file
+}
+
+export type NormalizedEvent = {
+ address: string,
+ event: string,
+ args: { [key: string]: string }
+};
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034/* eslint-disable function-call-argument-newline */5// eslint-disable-next-line @typescript-eslint/triple-slash-reference6/// <reference path="unique.dev.d.ts" />78import {readFile} from 'fs/promises';910import Web3 from 'web3';11import {WebsocketProvider} from 'web3-core';12import {Contract} from 'web3-eth-contract';1314import * as solc from 'solc';1516import {evmToAddress} from '@polkadot/util-crypto';17import {IKeyringPair} from '@polkadot/types/types';1819import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';2021import {ContractImports, CompiledContract} from './types';2223// Native contracts ABI24import collectionHelpersAbi from '../../collectionHelpersAbi.json';25import fungibleAbi from '../../fungibleAbi.json';26import nonFungibleAbi from '../../nonFungibleAbi.json';27import refungibleAbi from '../../reFungibleAbi.json';28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';29import contractHelpersAbi from './../contractHelpersAbi.json';30import {TEthereumAccount} from '../../../util/playgrounds/types';3132class EthGroupBase {33 helper: EthUniqueHelper;3435 constructor(helper: EthUniqueHelper) {36 this.helper = helper;37 }38}394041class ContractGroup extends EthGroupBase {42 async findImports(imports?: ContractImports[]){43 if(!imports) return function(path: string) {44 return {error: `File not found: ${path}`};45 };46 47 const knownImports = {} as {[key: string]: string};48 for(const imp of imports) {49 knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();50 }51 52 return function(path: string) {53 if(path in knownImports) return {contents: knownImports[path]};54 return {error: `File not found: ${path}`};55 };56 }5758 async compile(name: string, src: string, imports?: ContractImports[]): Promise<CompiledContract> {59 const out = JSON.parse(solc.compile(JSON.stringify({60 language: 'Solidity',61 sources: {62 [`${name}.sol`]: {63 content: src,64 },65 },66 settings: {67 outputSelection: {68 '*': {69 '*': ['*'],70 },71 },72 },73 }), {import: await this.findImports(imports)})).contracts[`${name}.sol`][name];74 75 return {76 abi: out.abi,77 object: '0x' + out.evm.bytecode.object,78 };79 }8081 async deployByCode(signer: string, name: string, src: string, imports?: ContractImports[]): Promise<Contract> {82 const compiledContract = await this.compile(name, src, imports);83 return this.deployByAbi(signer, compiledContract.abi, compiledContract.object);84 }8586 async deployByAbi(signer: string, abi: any, object: string): Promise<Contract> {87 const web3 = this.helper.getWeb3();88 const contract = new web3.eth.Contract(abi, undefined, {89 data: object,90 from: signer,91 gas: this.helper.eth.DEFAULT_GAS,92 });93 return await contract.deploy({data: object}).send({from: signer});94 }9596}97 98class NativeContractGroup extends EthGroupBase {99100 contractHelpers(caller: string): Contract {101 const web3 = this.helper.getWeb3();102 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, gas: this.helper.eth.DEFAULT_GAS});103 }104105 collectionHelpers(caller: string) {106 const web3 = this.helper.getWeb3();107 return new web3.eth.Contract(collectionHelpersAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, gas: this.helper.eth.DEFAULT_GAS});108 }109110 collection(address: string, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {111 const abi = {112 'nft': nonFungibleAbi,113 'rft': refungibleAbi,114 'ft': fungibleAbi,115 }[mode];116 const web3 = this.helper.getWeb3();117 return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});118 }119120 collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {121 return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller);122 }123124 rftToken(address: string, caller?: string): Contract {125 const web3 = this.helper.getWeb3();126 return new web3.eth.Contract(refungibleTokenAbi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});127 }128129 rftTokenById(collectionId: number, tokenId: number, caller?: string): Contract {130 return this.rftToken(this.helper.ethAddress.fromTokenId(collectionId, tokenId), caller);131 }132}133134135class EthGroup extends EthGroupBase {136 DEFAULT_GAS = 2_500_000;137138 createAccount() {139 const web3 = this.helper.getWeb3();140 const account = web3.eth.accounts.create();141 web3.eth.accounts.wallet.add(account.privateKey);142 return account.address;143 }144145 async createAccountWithBalance(donor: IKeyringPair, amount=1000n) {146 const account = this.createAccount();147 await this.transferBalanceFromSubstrate(donor, account, amount);148 149 return account;150 }151152 async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=1000n, inTokens=true) {153 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));154 }155 156 async getCollectionCreationFee(signer: string) {157 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);158 return await collectionHelper.methods.collectionCreationFee().call();159 }160161 async sendEVM(signer: IKeyringPair, contractAddress: string, abi: string, value: string, gasLimit?: number) {162 if(!gasLimit) gasLimit = this.DEFAULT_GAS;163 const web3 = this.helper.getWeb3();164 const gasPrice = await web3.eth.getGasPrice();165 // TODO: check execution status166 await this.helper.executeExtrinsic(167 signer,168 'api.tx.evm.call', [this.helper.address.substrateToEth(signer.address), contractAddress, abi, value, gasLimit, gasPrice, null, null, []],169 true,170 );171 }172173 async callEVM(signer: TEthereumAccount, contractAddress: string, abi: string) {174 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);175 }176177 async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {178 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();179 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);180 181 const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});182183 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);184 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);185186 return {collectionId, collectionAddress};187 }188189 async createRefungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {190 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();191 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);192 193 const result = await collectionHelper.methods.createRFTCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});194195 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);196 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);197198 return {collectionId, collectionAddress};199 }200201 async deployCollectorContract(signer: string): Promise<Contract> {202 return await this.helper.ethContract.deployByCode(signer, 'Collector', `203 // SPDX-License-Identifier: UNLICENSED204 pragma solidity ^0.8.6;205206 contract Collector {207 uint256 collected;208 fallback() external payable {209 giveMoney();210 }211 function giveMoney() public payable {212 collected += msg.value;213 }214 function getCollected() public view returns (uint256) {215 return collected;216 }217 function getUnaccounted() public view returns (uint256) {218 return address(this).balance - collected;219 }220221 function withdraw(address payable target) public {222 target.transfer(collected);223 collected = 0;224 }225 }226 `);227 }228229 async deployFlipper(signer: string): Promise<Contract> {230 return await this.helper.ethContract.deployByCode(signer, 'Flipper', `231 // SPDX-License-Identifier: UNLICENSED232 pragma solidity ^0.8.6;233234 contract Flipper {235 bool value = false;236 function flip() public {237 value = !value;238 }239 function getValue() public view returns (bool) {240 return value;241 }242 }243 `);244 }245246 async recordCallFee(user: string, call: () => Promise<any>): Promise<bigint> {247 const before = await this.helper.balance.getEthereum(user);248 await call();249 // In dev mode, the transaction might not finish processing in time250 await this.helper.wait.newBlocks(1);251 const after = await this.helper.balance.getEthereum(user);252253 return before - after;254 }255} 256257class EthAddressGroup extends EthGroupBase {258 extractCollectionId(address: string): number {259 if (!(address.length === 42 || address.length === 40)) throw new Error('address wrong format');260 return parseInt(address.substr(address.length - 8), 16);261 }262263 fromCollectionId(collectionId: number): string {264 if (collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');265 return Web3.utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8,'0')}`);266 }267268 extractTokenId(address: string): {collectionId: number, tokenId: number} {269 if (!address.startsWith('0x'))270 throw 'address not starts with "0x"';271 if (address.length > 42)272 throw 'address length is more than 20 bytes';273 return {274 collectionId: Number('0x' + address.substring(address.length - 16, address.length - 8)),275 tokenId: Number('0x' + address.substring(address.length - 8)),276 };277 }278279 fromTokenId(collectionId: number, tokenId: number): string {280 return this.helper.util.getTokenAddress({collectionId, tokenId});281 }282283 normalizeAddress(address: string): string {284 return '0x' + address.substring(address.length - 40);285 }286} 287 288289export class EthUniqueHelper extends DevUniqueHelper {290 web3: Web3 | null = null;291 web3Provider: WebsocketProvider | null = null;292293 eth: EthGroup;294 ethAddress: EthAddressGroup;295 ethNativeContract: NativeContractGroup;296 ethContract: ContractGroup;297298 constructor(logger: { log: (msg: any, level: any) => void, level: any }) {299 super(logger);300 this.eth = new EthGroup(this);301 this.ethAddress = new EthAddressGroup(this);302 this.ethNativeContract = new NativeContractGroup(this);303 this.ethContract = new ContractGroup(this);304 }305306 getWeb3(): Web3 {307 if(this.web3 === null) throw Error('Web3 not connected');308 return this.web3;309 }310311 async connectWeb3(wsEndpoint: string) {312 if(this.web3 !== null) return;313 this.web3Provider = new Web3.providers.WebsocketProvider(wsEndpoint);314 this.web3 = new Web3(this.web3Provider);315 }316317 async disconnectWeb3() {318 if(this.web3 === null) return;319 this.web3Provider?.connection.close();320 this.web3 = null;321 }322}323 1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034/* eslint-disable function-call-argument-newline */5// eslint-disable-next-line @typescript-eslint/triple-slash-reference6/// <reference path="unique.dev.d.ts" />78import {readFile} from 'fs/promises';910import Web3 from 'web3';11import {WebsocketProvider} from 'web3-core';12import {Contract} from 'web3-eth-contract';1314import * as solc from 'solc';1516import {evmToAddress} from '@polkadot/util-crypto';17import {IKeyringPair} from '@polkadot/types/types';1819import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';2021import {ContractImports, CompiledContract, NormalizedEvent} from './types';2223// Native contracts ABI24import collectionHelpersAbi from '../../collectionHelpersAbi.json';25import fungibleAbi from '../../fungibleAbi.json';26import nonFungibleAbi from '../../nonFungibleAbi.json';27import refungibleAbi from '../../reFungibleAbi.json';28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';29import contractHelpersAbi from './../contractHelpersAbi.json';30import {TEthereumAccount} from '../../../util/playgrounds/types';3132class EthGroupBase {33 helper: EthUniqueHelper;3435 constructor(helper: EthUniqueHelper) {36 this.helper = helper;37 }38}394041class ContractGroup extends EthGroupBase {42 async findImports(imports?: ContractImports[]){43 if(!imports) return function(path: string) {44 return {error: `File not found: ${path}`};45 };46 47 const knownImports = {} as {[key: string]: string};48 for(const imp of imports) {49 knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();50 }51 52 return function(path: string) {53 if(path in knownImports) return {contents: knownImports[path]};54 return {error: `File not found: ${path}`};55 };56 }5758 async compile(name: string, src: string, imports?: ContractImports[]): Promise<CompiledContract> {59 const out = JSON.parse(solc.compile(JSON.stringify({60 language: 'Solidity',61 sources: {62 [`${name}.sol`]: {63 content: src,64 },65 },66 settings: {67 outputSelection: {68 '*': {69 '*': ['*'],70 },71 },72 },73 }), {import: await this.findImports(imports)})).contracts[`${name}.sol`][name];74 75 return {76 abi: out.abi,77 object: '0x' + out.evm.bytecode.object,78 };79 }8081 async deployByCode(signer: string, name: string, src: string, imports?: ContractImports[]): Promise<Contract> {82 const compiledContract = await this.compile(name, src, imports);83 return this.deployByAbi(signer, compiledContract.abi, compiledContract.object);84 }8586 async deployByAbi(signer: string, abi: any, object: string): Promise<Contract> {87 const web3 = this.helper.getWeb3();88 const contract = new web3.eth.Contract(abi, undefined, {89 data: object,90 from: signer,91 gas: this.helper.eth.DEFAULT_GAS,92 });93 return await contract.deploy({data: object}).send({from: signer});94 }9596}97 98class NativeContractGroup extends EthGroupBase {99100 contractHelpers(caller: string): Contract {101 const web3 = this.helper.getWeb3();102 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, gas: this.helper.eth.DEFAULT_GAS});103 }104105 collectionHelpers(caller: string) {106 const web3 = this.helper.getWeb3();107 return new web3.eth.Contract(collectionHelpersAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, gas: this.helper.eth.DEFAULT_GAS});108 }109110 collection(address: string, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {111 const abi = {112 'nft': nonFungibleAbi,113 'rft': refungibleAbi,114 'ft': fungibleAbi,115 }[mode];116 const web3 = this.helper.getWeb3();117 return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});118 }119120 collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {121 return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller);122 }123124 rftToken(address: string, caller?: string): Contract {125 const web3 = this.helper.getWeb3();126 return new web3.eth.Contract(refungibleTokenAbi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});127 }128129 rftTokenById(collectionId: number, tokenId: number, caller?: string): Contract {130 return this.rftToken(this.helper.ethAddress.fromTokenId(collectionId, tokenId), caller);131 }132}133134135class EthGroup extends EthGroupBase {136 DEFAULT_GAS = 2_500_000;137138 createAccount() {139 const web3 = this.helper.getWeb3();140 const account = web3.eth.accounts.create();141 web3.eth.accounts.wallet.add(account.privateKey);142 return account.address;143 }144145 async createAccountWithBalance(donor: IKeyringPair, amount=1000n) {146 const account = this.createAccount();147 await this.transferBalanceFromSubstrate(donor, account, amount);148 149 return account;150 }151152 async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=1000n, inTokens=true) {153 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));154 }155 156 async getCollectionCreationFee(signer: string) {157 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);158 return await collectionHelper.methods.collectionCreationFee().call();159 }160161 async sendEVM(signer: IKeyringPair, contractAddress: string, abi: string, value: string, gasLimit?: number) {162 if(!gasLimit) gasLimit = this.DEFAULT_GAS;163 const web3 = this.helper.getWeb3();164 const gasPrice = await web3.eth.getGasPrice();165 // TODO: check execution status166 await this.helper.executeExtrinsic(167 signer,168 'api.tx.evm.call', [this.helper.address.substrateToEth(signer.address), contractAddress, abi, value, gasLimit, gasPrice, null, null, []],169 true,170 );171 }172173 async callEVM(signer: TEthereumAccount, contractAddress: string, abi: string) {174 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);175 }176177 async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {178 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();179 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);180 181 const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});182183 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);184 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);185186 return {collectionId, collectionAddress};187 }188189 async createRefungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {190 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();191 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);192 193 const result = await collectionHelper.methods.createRFTCollection(name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});194195 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);196 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);197198 return {collectionId, collectionAddress};199 }200201 async deployCollectorContract(signer: string): Promise<Contract> {202 return await this.helper.ethContract.deployByCode(signer, 'Collector', `203 // SPDX-License-Identifier: UNLICENSED204 pragma solidity ^0.8.6;205206 contract Collector {207 uint256 collected;208 fallback() external payable {209 giveMoney();210 }211 function giveMoney() public payable {212 collected += msg.value;213 }214 function getCollected() public view returns (uint256) {215 return collected;216 }217 function getUnaccounted() public view returns (uint256) {218 return address(this).balance - collected;219 }220221 function withdraw(address payable target) public {222 target.transfer(collected);223 collected = 0;224 }225 }226 `);227 }228229 async deployFlipper(signer: string): Promise<Contract> {230 return await this.helper.ethContract.deployByCode(signer, 'Flipper', `231 // SPDX-License-Identifier: UNLICENSED232 pragma solidity ^0.8.6;233234 contract Flipper {235 bool value = false;236 function flip() public {237 value = !value;238 }239 function getValue() public view returns (bool) {240 return value;241 }242 }243 `);244 }245246 async recordCallFee(user: string, call: () => Promise<any>): Promise<bigint> {247 const before = await this.helper.balance.getEthereum(user);248 await call();249 // In dev mode, the transaction might not finish processing in time250 await this.helper.wait.newBlocks(1);251 const after = await this.helper.balance.getEthereum(user);252253 return before - after;254 }255256 normalizeEvents(events: any): NormalizedEvent[] {257 const output = [];258 for (const key of Object.keys(events)) {259 if (key.match(/^[0-9]+$/)) {260 output.push(events[key]);261 } else if (Array.isArray(events[key])) {262 output.push(...events[key]);263 } else {264 output.push(events[key]);265 }266 }267 output.sort((a, b) => a.logIndex - b.logIndex);268 return output.map(({address, event, returnValues}) => {269 const args: { [key: string]: string } = {};270 for (const key of Object.keys(returnValues)) {271 if (!key.match(/^[0-9]+$/)) {272 args[key] = returnValues[key];273 }274 }275 return {276 address,277 event,278 args,279 };280 });281 }282} 283284class EthAddressGroup extends EthGroupBase {285 extractCollectionId(address: string): number {286 if (!(address.length === 42 || address.length === 40)) throw new Error('address wrong format');287 return parseInt(address.substr(address.length - 8), 16);288 }289290 fromCollectionId(collectionId: number): string {291 if (collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');292 return Web3.utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8,'0')}`);293 }294295 extractTokenId(address: string): {collectionId: number, tokenId: number} {296 if (!address.startsWith('0x'))297 throw 'address not starts with "0x"';298 if (address.length > 42)299 throw 'address length is more than 20 bytes';300 return {301 collectionId: Number('0x' + address.substring(address.length - 16, address.length - 8)),302 tokenId: Number('0x' + address.substring(address.length - 8)),303 };304 }305306 fromTokenId(collectionId: number, tokenId: number): string {307 return this.helper.util.getTokenAddress({collectionId, tokenId});308 }309310 normalizeAddress(address: string): string {311 return '0x' + address.substring(address.length - 40);312 }313} 314 315316export class EthUniqueHelper extends DevUniqueHelper {317 web3: Web3 | null = null;318 web3Provider: WebsocketProvider | null = null;319320 eth: EthGroup;321 ethAddress: EthAddressGroup;322 ethNativeContract: NativeContractGroup;323 ethContract: ContractGroup;324325 constructor(logger: { log: (msg: any, level: any) => void, level: any }) {326 super(logger);327 this.eth = new EthGroup(this);328 this.ethAddress = new EthAddressGroup(this);329 this.ethNativeContract = new NativeContractGroup(this);330 this.ethContract = new ContractGroup(this);331 }332333 getWeb3(): Web3 {334 if(this.web3 === null) throw Error('Web3 not connected');335 return this.web3;336 }337338 async connectWeb3(wsEndpoint: string) {339 if(this.web3 !== null) return;340 this.web3Provider = new Web3.providers.WebsocketProvider(wsEndpoint);341 this.web3 = new Web3(this.web3Provider);342 }343344 async disconnectWeb3() {345 if(this.web3 === null) return;346 this.web3Provider?.connection.close();347 this.web3 = null;348 }349}350