git.delta.rocks / unique-network / refs/commits / c50b56fb58cc

difftreelog

eth/proxy/nonFungibleProxy migrated

rkv2022-09-28parent: #3fb65c0.patch.diff
in: master

1 file changed

modifiedtests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// 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/>.
1616
17import {createCollectionExpectSuccess, createItemExpectSuccess} from '../../util/helpers';17import {GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents} from '../util/helpers';
19import nonFungibleAbi from '../nonFungibleAbi.json';
20import {expect} from 'chai';18import {expect} from 'chai';
21import {submitTransactionAsync} from '../../substrate/substrate-api';
22import Web3 from 'web3';
23import {readFile} from 'fs/promises';19import {readFile} from 'fs/promises';
24import {ApiPromise} from '@polkadot/api';
25import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util/playgrounds';
2622
27async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any, privateKeyWrapper: (account: string) => IKeyringPair) {23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {
28 // 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 them
29 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25 const owner = await helper.eth.createAccountWithBalance(donor);
30 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {26 const proxyContract = new helper.web3!.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {
31 from: owner,27 from: owner,
32 ...GAS_ARGS,28 ...GAS_ARGS,
33 });29 });
36}32}
3733
38describe('NFT (Via EVM proxy): Information getting', () => {34describe('NFT (Via EVM proxy): Information getting', () => {
39 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {35 let alice: IKeyringPair;
36 let donor: IKeyringPair;
37
38 before(async function() {
39 await usingEthPlaygrounds(async (helper, privateKey) => {
40 const collection = await createCollectionExpectSuccess({40 donor = privateKey('//Alice');
41 mode: {type: 'NFT'},41 [alice] = await helper.arrange.createAccounts([10n], donor);
42 });42 });
43 const alice = privateKeyWrapper('//Alice');43 });
44 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
4544
46 await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});45 itEth('totalSupply', async ({helper}) => {
46 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
47 const caller = await helper.eth.createAccountWithBalance(donor);
48 await collection.mintToken(alice, {Substrate: alice.address});
4749
48 const address = collectionIdToAddress(collection);50 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
49 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);51 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
52 const contract = await proxyWrap(helper, evmCollection, donor);
50 const totalSupply = await contract.methods.totalSupply().call();53 const totalSupply = await contract.methods.totalSupply().call();
5154
52 expect(totalSupply).to.equal('1');55 expect(totalSupply).to.equal('1');
53 });56 });
5457
55 itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {58 itEth('balanceOf', async ({helper}) => {
56 const collection = await createCollectionExpectSuccess({59 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
57 mode: {type: 'NFT'},
58 });
59 const alice = privateKeyWrapper('//Alice');
6060
61 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);61 const caller = await helper.eth.createAccountWithBalance(donor);
62 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});62 await collection.mintMultipleTokens(alice, [
63 {owner: {Ethereum: caller}},
63 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});64 {owner: {Ethereum: caller}},
64 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});65 {owner: {Ethereum: caller}},
66 ]);
6567
66 const address = collectionIdToAddress(collection);68 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
67 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);69 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
70 const contract = await proxyWrap(helper, evmCollection, donor);
68 const balance = await contract.methods.balanceOf(caller).call();71 const balance = await contract.methods.balanceOf(caller).call();
6972
70 expect(balance).to.equal('3');73 expect(balance).to.equal('3');
71 });74 });
7275
73 itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {76 itEth('ownerOf', async ({helper}) => {
74 const collection = await createCollectionExpectSuccess({77 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
75 mode: {type: 'NFT'},
76 });
77 const alice = privateKeyWrapper('//Alice');
7878
79 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);79 const caller = await helper.eth.createAccountWithBalance(donor);
80 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});80 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});
8181
82 const address = collectionIdToAddress(collection);82 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
83 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);83 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
84 const contract = await proxyWrap(helper, evmCollection, donor);
84 const owner = await contract.methods.ownerOf(tokenId).call();85 const owner = await contract.methods.ownerOf(tokenId).call();
8586
86 expect(owner).to.equal(caller);87 expect(owner).to.equal(caller);
87 });88 });
88});89});
8990
90describe('NFT (Via EVM proxy): Plain calls', () => {91describe('NFT (Via EVM proxy): Plain calls', () => {
91 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {92 let alice: IKeyringPair;
93 let donor: IKeyringPair;
94
95 before(async function() {
96 await usingEthPlaygrounds(async (helper, privateKey) => {
92 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);97 donor = privateKey('//Alice');
93 const collectionHelper = evmCollectionHelpers(web3, owner);98 [alice] = await helper.arrange.createAccounts([10n], donor);
94 const result = await collectionHelper.methods99 });
100 });
101
95 .createNonfungibleCollection('A', 'A', 'A')102 itEth('Can perform mint()', async ({helper}) => {
96 .send();103 const owner = await helper.eth.createAccountWithBalance(donor);
97 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);104 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'A', 'A');
98 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);105 const caller = await helper.eth.createAccountWithBalance(donor);
99 const receiver = createEthAccount(web3);106 const receiver = helper.eth.createAccount();
107
100 const collectionEvmOwned = evmCollection(web3, owner, collectionIdAddress);108 const collectionEvmOwned = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
101 const collectionEvm = evmCollection(web3, caller, collectionIdAddress);109 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);
102 const contract = await proxyWrap(api, web3, collectionEvm, privateKeyWrapper);110 const contract = await proxyWrap(helper, collectionEvm, donor);
103 await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();111 await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();
104112
105 {113 {
115123
116 expect(events).to.be.deep.equal([124 expect(events).to.be.deep.equal([
117 {125 {
118 address: collectionIdAddress.toLocaleLowerCase(),126 address: collectionAddress.toLocaleLowerCase(),
119 event: 'Transfer',127 event: 'Transfer',
120 args: {128 args: {
121 from: '0x0000000000000000000000000000000000000000',129 from: '0x0000000000000000000000000000000000000000',
128 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');136 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
129 }137 }
130 });138 });
131 139
132 //TODO: CORE-302 add eth methods140 //TODO: CORE-302 add eth methods
133 itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {141 itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {
142 /*
134 const collection = await createCollectionExpectSuccess({143 const collection = await createCollectionExpectSuccess({
135 mode: {type: 'NFT'},144 mode: {type: 'NFT'},
136 });145 });
191 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');200 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
192 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');201 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
193 }202 }
203 */
194 });204 });
195205
196 itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {206 itEth('Can perform burn()', async ({helper}) => {
197 const collection = await createCollectionExpectSuccess({207 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
198 mode: {type: 'NFT'},
199 });
200 const alice = privateKeyWrapper('//Alice');
201 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);208 const caller = await helper.eth.createAccountWithBalance(donor);
202209
203 const address = collectionIdToAddress(collection);210 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
204 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);211 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
212 const contract = await proxyWrap(helper, evmCollection, donor);
205 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});213 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});
214 await collection.addAdmin(alice, {Ethereum: contract.options.address});
206215
207 const changeAdminTx = api.tx.unique.addCollectionAdmin(collection, {Ethereum: contract.options.address});
208 await submitTransactionAsync(alice, changeAdminTx);
209
210 {216 {
211 const result = await contract.methods.burn(tokenId).send({from: caller});217 const result = await contract.methods.burn(tokenId).send({from: caller});
212 const events = normalizeEvents(result.events);218 const events = normalizeEvents(result.events);
225 }231 }
226 });232 });
227233
228 itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {234 itEth('Can perform approve()', async ({helper}) => {
229 const collection = await createCollectionExpectSuccess({235 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
230 mode: {type: 'NFT'},
231 });
232 const alice = privateKeyWrapper('//Alice');
233 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);236 const caller = await helper.eth.createAccountWithBalance(donor);
234 const spender = createEthAccount(web3);237 const spender = helper.eth.createAccount();
235238
236 const address = collectionIdToAddress(collection);239 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
237 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address), privateKeyWrapper);240 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
241 const contract = await proxyWrap(helper, evmCollection, donor);
238 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});242 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});
239243
240 {244 {
241 const result = await contract.methods.approve(spender, tokenId).send({from: caller, ...GAS_ARGS});245 const result = await contract.methods.approve(spender, tokenId).send({from: caller, ...GAS_ARGS});
255 }259 }
256 });260 });
257261
258 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {262 itEth('Can perform transferFrom()', async ({helper}) => {
259 const collection = await createCollectionExpectSuccess({263 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
260 mode: {type: 'NFT'},
261 });
262 const alice = privateKeyWrapper('//Alice');
263 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);264 const caller = await helper.eth.createAccountWithBalance(donor);
264 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);265 const owner = await helper.eth.createAccountWithBalance(donor);
265266
266 const receiver = createEthAccount(web3);267 const receiver = helper.eth.createAccount();
267268
268 const address = collectionIdToAddress(collection);269 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
269 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});270 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
270 const contract = await proxyWrap(api, web3, evmCollection, privateKeyWrapper);271 const contract = await proxyWrap(helper, evmCollection, donor);
271 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});272 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});
272273
273 await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});274 await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});
274275
299 }300 }
300 });301 });
301302
302 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {303 itEth('Can perform transfer()', async ({helper}) => {
303 const collection = await createCollectionExpectSuccess({304 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
304 mode: {type: 'NFT'},
305 });
306 const alice = privateKeyWrapper('//Alice');
307 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);305 const caller = await helper.eth.createAccountWithBalance(donor);
308 const receiver = createEthAccount(web3);306 const receiver = helper.eth.createAccount();
309307
310 const address = collectionIdToAddress(collection);308 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
311 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);309 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
310 const contract = await proxyWrap(helper, evmCollection, donor);
312 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});311 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});
313312
314 {313 {
315 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});314 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});