difftreelog
fix eth tests
in: master
5 files changed
tests/src/eth/base.test.tsdiffbeforeafterboth232324import {IKeyringPair} from '@polkadot/types/types';24import {IKeyringPair} from '@polkadot/types/types';25import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';25import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';26import {UNIQUE} from '../util/helpers';272628describe('Contract calls', () => {27describe('Contract calls', () => {29 let donor: IKeyringPair;28 let donor: IKeyringPair;39 const flipper = await helper.eth.deployFlipper(deployer);38 const flipper = await helper.eth.deployFlipper(deployer);403941 const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));40 const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));42 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;41 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;43 });42 });444345 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {44 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {46 const userA = await helper.eth.createAccountWithBalance(donor);45 const userA = await helper.eth.createAccountWithBalance(donor);47 const userB = helper.eth.createAccount();46 const userB = helper.eth.createAccount();48 const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));47 const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));49 const balanceB = await ethBalanceViaSub(helper.api!, userB);48 const balanceB = await ethBalanceViaSub(helper.api!, userB);50 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;49 expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;51 });50 });525153 itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {52 itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {636264 const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));63 const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));656466 const fee = Number(cost) / Number(UNIQUE);65 const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());67 const expectedFee = 0.15;66 const expectedFee = 0.15;68 const tolerance = 0.001;67 const tolerance = 0.001;6968tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.151516import {IKeyringPair} from '@polkadot/types/types';16import {IKeyringPair} from '@polkadot/types/types';17import {UNIQUE} from '../util/helpers';17import {usingEthPlaygrounds, itEth, expect, EthUniqueHelper} from './util/playgrounds';1819async function waitNewBlocks(helper: EthUniqueHelper, count: number) {20 // eslint-disable-next-line no-async-promise-executor18import {21 return new Promise<void>(async (resolve) => {19 recordEthFee,22 const unsubscribe = await helper.callRpc('api.rpc.chain.subscribeNewHeads', [() => {23 if (count > 0) {24 count--;25 } else {26 unsubscribe();27 resolve();28 }29 }]);20} from './util/helpers';30 });31}3221import {usingEthPlaygrounds, itEth, expect} from './util/playgrounds';33async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {34 const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));35 await call();36 waitNewBlocks(helper, 1);37 const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));3839 expect(after < before).to.be.true;4041 return before - after;42}224323describe('Add collection admins', () => {44describe('Add collection admins', () => {24 let donor: IKeyringPair;45 let donor: IKeyringPair;37 const newAdmin = helper.eth.createAccount();58 const newAdmin = helper.eth.createAccount();385939 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();60 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();40 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);61 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);41 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())62 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())42 .to.be.eq(newAdmin.toLocaleLowerCase());63 .to.be.eq(newAdmin.toLocaleLowerCase());43 });64 });50 const [newAdmin] = await helper.arrange.createAccounts([10n], donor);71 const [newAdmin] = await helper.arrange.createAccounts([10n], donor);51 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();72 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();527353 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);74 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);54 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())75 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())55 .to.be.eq(newAdmin.address.toLocaleLowerCase());76 .to.be.eq(newAdmin.address.toLocaleLowerCase());56 });77 });577858 //FIXME:59 itEth('Verify owner or admin', async ({helper}) => {79 itEth('Verify owner or admin', async ({helper}) => {60 const owner = await helper.eth.createAccountWithBalance(donor);80 const owner = await helper.eth.createAccountWithBalance(donor);61 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');81 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');79 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))99 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))80 .to.be.rejectedWith('NoPermission');100 .to.be.rejectedWith('NoPermission');8110182 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);102 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);83 expect(adminList.length).to.be.eq(1);103 expect(adminList.length).to.be.eq(1);84 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())104 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())85 .to.be.eq(admin.toLocaleLowerCase());105 .to.be.eq(admin.toLocaleLowerCase());96 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))116 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))97 .to.be.rejectedWith('NoPermission');117 .to.be.rejectedWith('NoPermission');9811899 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);119 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);100 expect(adminList.length).to.be.eq(0);120 expect(adminList.length).to.be.eq(0);101 });121 });102122112 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))132 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))113 .to.be.rejectedWith('NoPermission');133 .to.be.rejectedWith('NoPermission');114134115 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);135 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);116 expect(adminList.length).to.be.eq(1);136 expect(adminList.length).to.be.eq(1);117 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())137 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())118 .to.be.eq(admin.toLocaleLowerCase());138 .to.be.eq(admin.toLocaleLowerCase());128 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))148 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))129 .to.be.rejectedWith('NoPermission');149 .to.be.rejectedWith('NoPermission');130150131 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);151 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);132 expect(adminList.length).to.be.eq(0);152 expect(adminList.length).to.be.eq(0);133 });153 });134});154});151 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();171 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();152172153 {173 {154 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);174 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);155 expect(adminList.length).to.be.eq(1);175 expect(adminList.length).to.be.eq(1);156 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())176 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())157 .to.be.eq(newAdmin.toLocaleLowerCase());177 .to.be.eq(newAdmin.toLocaleLowerCase());158 }178 }159179160 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();180 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();161 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);181 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);162 expect(adminList.length).to.be.eq(0);182 expect(adminList.length).to.be.eq(0);163 });183 });164184170 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);190 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);171 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();191 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();172 {192 {173 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);193 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);174 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())194 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())175 .to.be.eq(newAdmin.address.toLocaleLowerCase());195 .to.be.eq(newAdmin.address.toLocaleLowerCase());176 }196 }177197178 await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();198 await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();179 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);199 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);180 expect(adminList.length).to.be.eq(0);200 expect(adminList.length).to.be.eq(0);181 });201 });182202194 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))214 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))195 .to.be.rejectedWith('NoPermission');215 .to.be.rejectedWith('NoPermission');196 {216 {197 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);217 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);198 expect(adminList.length).to.be.eq(2);218 expect(adminList.length).to.be.eq(2);199 expect(adminList.toString().toLocaleLowerCase())219 expect(adminList.toString().toLocaleLowerCase())200 .to.be.deep.contains(admin0.toLocaleLowerCase())220 .to.be.deep.contains(admin0.toLocaleLowerCase())215 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))235 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))216 .to.be.rejectedWith('NoPermission');236 .to.be.rejectedWith('NoPermission');217 {237 {218 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);238 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);219 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())239 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())220 .to.be.eq(admin.toLocaleLowerCase());240 .to.be.eq(admin.toLocaleLowerCase());221 expect(adminList.length).to.be.eq(1);241 expect(adminList.length).to.be.eq(1);235 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))255 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))236 .to.be.rejectedWith('NoPermission');256 .to.be.rejectedWith('NoPermission');237257238 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);258 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);239 expect(adminList.length).to.be.eq(2);259 expect(adminList.length).to.be.eq(2);240 expect(adminList.toString().toLocaleLowerCase())260 expect(adminList.toString().toLocaleLowerCase())241 .to.be.deep.contains(adminSub.address.toLocaleLowerCase())261 .to.be.deep.contains(adminSub.address.toLocaleLowerCase())254 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))274 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))255 .to.be.rejectedWith('NoPermission');275 .to.be.rejectedWith('NoPermission');256276257 const adminList = await helper.api!.rpc.unique.adminlist(collectionId);277 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);258 expect(adminList.length).to.be.eq(1);278 expect(adminList.length).to.be.eq(1);259 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())279 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())260 .to.be.eq(adminSub.address.toLocaleLowerCase());280 .to.be.eq(adminSub.address.toLocaleLowerCase());288 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');308 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');289 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);309 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);290291 const cost = await recordEthFee(helper.api!, owner, () => collectionEvm.methods.setOwner(newOwner).send());310 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwner(newOwner).send());292 expect(cost < BigInt(0.2 * Number(UNIQUE)));311 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));293 expect(cost > 0);312 expect(cost > 0);294 });313 });295314296 //FIXME297 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {315 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {298 const owner = await helper.eth.createAccountWithBalance(donor);316 const owner = await helper.eth.createAccountWithBalance(donor);299 const newOwner = await helper.eth.createAccountWithBalance(donor);317 const newOwner = await helper.eth.createAccountWithBalance(donor);314 });332 });315 });333 });316334317 //FIXME318 itEth.skip('Change owner', async ({helper}) => {335 itEth.skip('Change owner', async ({helper}) => {319 const owner = await helper.eth.createAccountWithBalance(donor);336 const owner = await helper.eth.createAccountWithBalance(donor);320 const [newOwner] = await helper.arrange.createAccounts([10n], donor);337 const [newOwner] = await helper.arrange.createAccounts([10n], donor);336 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');353 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');337 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);354 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);338355339 const cost = await recordEthFee(helper.api!, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());356 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());340 expect(cost < BigInt(0.2 * Number(UNIQUE)));357 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));341 expect(cost > 0);358 expect(cost > 0);342 });359 });343360344 //FIXME345 itEth.skip('(!negative tests!) call setOwner by non owner', async ({helper}) => {361 itEth.skip('(!negative tests!) call setOwner by non owner', async ({helper}) => {346 const owner = await helper.eth.createAccountWithBalance(donor);362 const owner = await helper.eth.createAccountWithBalance(donor);347 const otherReceiver = await helper.eth.createAccountWithBalance(donor);363 const otherReceiver = await helper.eth.createAccountWithBalance(donor);tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth51 const contract = helper.ethNativeContract.collection(address, 'nft', caller);51 const contract = helper.ethNativeContract.collection(address, 'nft', caller);525253 const value = await contract.methods.collectionProperty('testKey').call();53 const value = await contract.methods.collectionProperty('testKey').call();54 expect(value).to.equal(helper.web3?.utils.toHex('testValue'));54 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));55 });55 });56});56});5757tests/src/eth/proxy/fungibleProxy.test.tsdiffbeforeafterboth23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {24 // Proxy owner has no special privilegies, we don't need to reuse them24 // Proxy owner has no special privilegies, we don't need to reuse them25 const owner = await helper.eth.createAccountWithBalance(donor);25 const owner = await helper.eth.createAccountWithBalance(donor);26 const web3 = helper.getWeb3();26 const proxyContract = new helper.web3!.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {27 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {27 from: owner,28 from: owner,28 ...GAS_ARGS,29 ...GAS_ARGS,29 });30 });tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {24 // Proxy owner has no special privilegies, we don't need to reuse them24 // Proxy owner has no special privilegies, we don't need to reuse them25 const owner = await helper.eth.createAccountWithBalance(donor);25 const owner = await helper.eth.createAccountWithBalance(donor);26 const web3 = helper.getWeb3();26 const proxyContract = new helper.web3!.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {27 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {27 from: owner,28 from: owner,28 ...GAS_ARGS,29 ...GAS_ARGS,29 });30 });