difftreelog
CORE-346 Some changes for broken tests
in: master
5 files changed
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth29 normalizeEvents,29 normalizeEvents,30 subToEth,30 subToEth,31 executeEthTxOnSub,31 executeEthTxOnSub,32 evmCollectionHelper,33 getCollectionAddressFromResult,34 evmCollection,32} from './util/helpers';35} from './util/helpers';33import {36import {34 addCollectionAdminExpectSuccess,37 addCollectionAdminExpectSuccess,35 createCollectionExpectSuccess,38 createCollectionExpectSuccess,36 getCreateCollectionResult,39 getCreateCollectionResult,40 getDetailedCollectionInfo,37 transferBalanceTo,41 transferBalanceTo,38} from '../util/helpers';42} from '../util/helpers';39import nonFungibleAbi from './nonFungibleAbi.json';43import nonFungibleAbi from './nonFungibleAbi.json';42} from '../substrate/substrate-api';46} from '../substrate/substrate-api';43import getBalance from '../substrate/get-balance';47import getBalance from '../substrate/get-balance';44import {alicesPublicKey} from '../accounts';48import {alicesPublicKey} from '../accounts';49import { evmToAddress } from '@polkadot/util-crypto';455046describe('Sponsoring EVM contracts', () => {51describe('Sponsoring EVM contracts', () => {47 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {52 itWeb3('Sponsoring can be set by the address that has deployed the contract', async ({api, web3}) => {222 });227 });223228224 itWeb3('Sponsoring evm address from substrate collection', async ({api, web3}) => {229 itWeb3('Sponsoring evm address from substrate collection', async ({api, web3}) => {225 const owner = privateKey('//Alice');230 const owner = await createEthAccountWithBalance(api, web3);226 const userEth = createEthAccount(web3);231 const collectionHelper = evmCollectionHelper(web3, owner);227 const collectionId = await createCollectionExpectSuccess();232 let result = await collectionHelper.methods.create721Collection('Sponsor collection', '1', '1').send();228229 {230 const tx = api.tx.unique.setCollectionSponsor(collectionId, owner.address);233 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);231 const events = await submitTransactionAsync(owner, tx);234 const sponsor = await createEthAccountWithBalance(api, web3);232 const result = getCreateCollectionResult(events);235 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);233 expect(result.success).to.be.true;234 }235 {236 const tx = api.tx.unique.confirmSponsorship(collectionId);236 result = await collectionEvm.methods.ethSetSponsor(sponsor).send();237 const events = await submitTransactionAsync(owner, tx);237 let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;238 const result = getCreateCollectionResult(events);239 expect(result.success).to.be.true;238 expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;240 }241242 const address = collectionIdToAddress(collectionId);243 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: userEth, ...GAS_ARGS});244245 { // This part should fail, because user not in access list and user have no money246 const nextTokenId = await contract.methods.nextTokenId().call();247 expect(nextTokenId).to.be.equal('1');239 expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));248 await expect(contract.methods.mintWithTokenURI(240 await expect(collectionEvm.methods.ethConfirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');249 userEth,241250 nextTokenId,251 'Test URI',252 ).call({from: userEth})).to.be.rejectedWith(/PublicMintingNotAllowed/);253 }254255 {256 const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');242 const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);257 const events = await submitTransactionAsync(owner, tx);243 await sponsorCollection.methods.ethConfirmSponsorship().send();258 const result = getCreateCollectionResult(events);244 collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;259 expect(result.success).to.be.true;245 expect(collectionSub.sponsorship.isConfirmed).to.be.true;260 }261 {262 const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});263 const events = await submitTransactionAsync(owner, tx);264 const result = getCreateCollectionResult(events);265 expect(result.success).to.be.true;246 expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));266 }247267 {268 const tx = api.tx.unique.setMintPermission(collectionId, true);248 const user = createEthAccount(web3);269 const events = await submitTransactionAsync(owner, tx);249 const userContract = evmCollection(web3, user, collectionIdAddress);270 const result = getCreateCollectionResult(events);250 const nextTokenId = await userContract.methods.nextTokenId().call();251271 expect(result.success).to.be.true;252 expect(nextTokenId).to.be.equal('1');272 }273274 const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);253 await expect(userContract.methods.mintWithTokenURI(254 user,255 nextTokenId,256 'Test URI',257 ).call()).to.be.rejectedWith('PublicMintingNotAllowed');258 259 // TODO: add this methods to eth260 // {261 // const tx = api.tx.unique.setPublicAccessMode(collectionId, 'AllowList');262 // const events = await submitTransactionAsync(owner, tx);263 // const result = getCreateCollectionResult(events);264 // expect(result.success).to.be.true;265 // }266 // {267 // const tx = api.tx.unique.addToAllowList(collectionId, {Ethereum: userEth});268 // const events = await submitTransactionAsync(owner, tx);269 // const result = getCreateCollectionResult(events);270 // expect(result.success).to.be.true;271 // }272 // {273 // const tx = api.tx.unique.setMintPermission(collectionId, true);274 // const events = await submitTransactionAsync(owner, tx);275 // const result = getCreateCollectionResult(events);276 // expect(result.success).to.be.true;277 // }278279 // const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);275280276 {281 {277 const nextTokenId = await contract.methods.nextTokenId().call();282 const nextTokenId = await userContract.methods.nextTokenId().call();278 expect(nextTokenId).to.be.equal('1');283 expect(nextTokenId).to.be.equal('1');279 const result = await contract.methods.mintWithTokenURI(284 const result = await userContract.methods.mintWithTokenURI(280 userEth,285 user,281 nextTokenId,286 nextTokenId,282 'Test URI',287 'Test URI',283 ).send({from: userEth});288 ).send();284 const events = normalizeEvents(result.events);289 const events = normalizeEvents(result.events);285290286 expect(events).to.be.deep.equal([291 expect(events).to.be.deep.equal([287 {292 {288 address,293 collectionIdAddress,289 event: 'Transfer',294 event: 'Transfer',290 args: {295 args: {291 from: '0x0000000000000000000000000000000000000000',296 from: '0x0000000000000000000000000000000000000000',292 to: userEth,297 to: user,293 tokenId: nextTokenId,298 tokenId: nextTokenId,294 },299 },295 },300 },296 ]);301 ]);297302298 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');303 expect(await userContract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');299 }304 }300301 const [alicesBalanceAfter] = await getBalance(api, [alicesPublicKey]);302 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;303 });305 });304306305307tests/src/eth/createCollection.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import nonFungibleAbi from './nonFungibleAbi.json';18import {ApiPromise} from '@polkadot/api';19import {evmToAddress} from '@polkadot/util-crypto';17import {evmToAddress} from '@polkadot/util-crypto';20import {expect} from 'chai';18import {expect} from 'chai';21import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';19import {getCreatedCollectionCount, getDetailedCollectionInfo} from '../util/helpers';22import {20import {23 evmCollectionHelper,21 evmCollectionHelper,24 collectionIdFromAddress,25 collectionIdToAddress,22 collectionIdToAddress,26 createEthAccount,23 createEthAccount,27 createEthAccountWithBalance,24 createEthAccountWithBalance,28 evmCollection,25 evmCollection,29 GAS_ARGS,30 itWeb3,26 itWeb3,31 normalizeAddress,27 getCollectionAddressFromResult,32 normalizeEvents,33} from './util/helpers';28} from './util/helpers';3435async function getCollectionAddressFromResult(api: ApiPromise, result: any) {36 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);37 const collectionId = collectionIdFromAddress(collectionIdAddress); 38 const collection = (await getDetailedCollectionInfo(api, collectionId))!;39 return {collectionIdAddress, collectionId, collection};40}412942describe('Create collection from EVM', () => {30describe('Create collection from EVM', () => {43 itWeb3('Create collection', async ({api, web3}) => {31 itWeb3('Create collection', async ({api, web3}) => {140 expect(collectionSub.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);128 expect(collectionSub.limits.transfersEnabled.toHuman()).to.be.eq(limits.transfersEnabled);141 });129 });142143 itWeb3('Check tokenURI', async ({web3, api}) => {144 const owner = await createEthAccountWithBalance(api, web3);145 const helper = evmCollectionHelper(web3, owner);146 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();147 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);148 const receiver = createEthAccount(web3);149 const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress, {from: owner, ...GAS_ARGS});150 const nextTokenId = await contract.methods.nextTokenId().call();151152 expect(nextTokenId).to.be.equal('1');153 result = await contract.methods.mintWithTokenURI(154 receiver,155 nextTokenId,156 'Test URI',157 ).send();158159 const events = normalizeEvents(result.events);160 const address = collectionIdToAddress(collectionId);161162 expect(events).to.be.deep.equal([163 {164 address,165 event: 'Transfer',166 args: {167 from: '0x0000000000000000000000000000000000000000',168 to: receiver,169 tokenId: nextTokenId,170 },171 },172 ]);173174 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');175176 // TODO: this wont work right now, need release 919000 first177 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();178 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();179 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);180 });181130182 itWeb3('Collection address exist', async ({api, web3}) => {131 itWeb3('Collection address exist', async ({api, web3}) => {183 const owner = await createEthAccountWithBalance(api, web3);132 const owner = await createEthAccountWithBalance(api, web3);tests/src/eth/nonFungible.test.tsdiffbeforeafterboth161617import privateKey from '../substrate/privateKey';17import privateKey from '../substrate/privateKey';18import {approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';18import {approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';19import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';19import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelper, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';20import nonFungibleAbi from './nonFungibleAbi.json';20import nonFungibleAbi from './nonFungibleAbi.json';21import {expect} from 'chai';21import {expect} from 'chai';22import {submitTransactionAsync} from '../substrate/substrate-api';22import {submitTransactionAsync} from '../substrate/substrate-api';757576describe('NFT: Plain calls', () => {76describe('NFT: Plain calls', () => {77 itWeb3('Can perform mint()', async ({web3, api}) => {77 itWeb3('Can perform mint()', async ({web3, api}) => {78 const collection = await createCollectionExpectSuccess({78 const owner = await createEthAccountWithBalance(api, web3);79 mode: {type: 'NFT'},80 });81 const alice = privateKey('//Alice');8283 const caller = await createEthAccountWithBalance(api, web3);79 const helper = evmCollectionHelper(web3, owner);84 const changeAdminTx = api.tx.unique.addCollectionAdmin(collection, {Ethereum: caller});80 let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();85 await submitTransactionAsync(alice, changeAdminTx);81 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);86 const receiver = createEthAccount(web3);82 const receiver = createEthAccount(web3);8788 const address = collectionIdToAddress(collection);89 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});83 const contract = evmCollection(web3, owner, collectionIdAddress);9091 {92 const nextTokenId = await contract.methods.nextTokenId().call();84 const nextTokenId = await contract.methods.nextTokenId().call();8593 expect(nextTokenId).to.be.equal('1');86 expect(nextTokenId).to.be.equal('1');94 const result = await contract.methods.mintWithTokenURI(87 result = await contract.methods.mintWithTokenURI(95 receiver,88 receiver,96 nextTokenId,89 nextTokenId,97 'Test URI',90 'Test URI',98 ).send({from: caller});91 ).send();9299 const events = normalizeEvents(result.events);93 const events = normalizeEvents(result.events);94 const address = collectionIdToAddress(collectionId);10095101 expect(events).to.be.deep.equal([96 expect(events).to.be.deep.equal([102 {97 {111 ]);106 ]);112107113 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');108 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');114 }109110 // TODO: this wont work right now, need release 919000 first111 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();112 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();113 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);115 });114 });116 itWeb3('Can perform mintBulk()', async ({web3, api}) => {115 itWeb3('Can perform mintBulk()', async ({web3, api}) => {117 const collection = await createCollectionExpectSuccess({116 const collection = await createCollectionExpectSuccess({tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterbothno syntactic changes
tests/src/eth/util/helpers.tsdiffbeforeafterboth23import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';23import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';24import {IKeyringPair} from '@polkadot/types/types';24import {IKeyringPair} from '@polkadot/types/types';25import {expect} from 'chai';25import {expect} from 'chai';26import {CrossAccountId, getGenericResult, UNIQUE} from '../../util/helpers';26import {CrossAccountId, getDetailedCollectionInfo, getGenericResult, UNIQUE} from '../../util/helpers';27import * as solc from 'solc';27import * as solc from 'solc';28import config from '../../config';28import config from '../../config';29import privateKey from '../../substrate/privateKey';29import privateKey from '../../substrate/privateKey';30import contractHelpersAbi from './contractHelpersAbi.json';30import contractHelpersAbi from './contractHelpersAbi.json';31import collectionAbi from '../nonFungibleAbi.json';31import nonFungibleAbi from '../nonFungibleAbi.json';32import collectionHelperAbi from '../collectionHelperAbi.json';32import collectionHelperAbi from '../collectionHelperAbi.json';33import getBalance from '../../substrate/get-balance';33import getBalance from '../../substrate/get-balance';34import waitNewBlocks from '../../substrate/wait-new-blocks';34import waitNewBlocks from '../../substrate/wait-new-blocks';68 ];68 ];69}69}7071export async function getCollectionAddressFromResult(api: ApiPromise, result: any) {72 const collectionIdAddress = normalizeAddress(result.events[0].raw.topics[2]);73 const collectionId = collectionIdFromAddress(collectionIdAddress); 74 const collection = (await getDetailedCollectionInfo(api, collectionId))!;75 return {collectionIdAddress, collectionId, collection};76}707771export function collectionIdToAddress(collection: number): string {78export function collectionIdToAddress(collection: number): string {72 const buf = Buffer.from([0x17, 0xc4, 0xe6, 0x45, 0x3c, 0xc4, 0x9a, 0xaa, 0xae, 0xac, 0xa8, 0x94, 0xe6, 0xd9, 0x68, 0x3e,79 const buf = Buffer.from([0x17, 0xc4, 0xe6, 0x45, 0x3c, 0xc4, 0x9a, 0xaa, 0xae, 0xac, 0xa8, 0x94, 0xe6, 0xd9, 0x68, 0x3e,301 * @returns 308 * @returns 302 */309 */303export function evmCollection(web3: Web3, caller: string, collection: string) {310export function evmCollection(web3: Web3, caller: string, collection: string) {304 return new web3.eth.Contract(collectionAbi as any, collection, {from: caller, ...GAS_ARGS});311 return new web3.eth.Contract(nonFungibleAbi as any, collection, {from: caller, ...GAS_ARGS});305}312}306313307/**314/**