git.delta.rocks / unique-network / refs/commits / 3fb65c0d79a1

difftreelog

eth/proxy/fungibleProxy migrated

rkv2022-09-28parent: #759b871.patch.diff
in: master

1 file changed

modifiedtests/src/eth/proxy/fungibleProxy.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, createFungibleItemExpectSuccess} from '../../util/helpers';
18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';17import {GAS_ARGS, normalizeEvents} from '../util/helpers';
19import fungibleAbi from '../fungibleAbi.json';
20import {expect} from 'chai';18import {expect} from 'chai';
21import {ApiPromise} from '@polkadot/api';
22import Web3 from 'web3';
23import {readFile} from 'fs/promises';19import {readFile} from 'fs/promises';
24import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util/playgrounds';
2522
26async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any, privateKeyWrapper: (account: string) => IKeyringPair) {23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {
27 // 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
28 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25 const owner = await helper.eth.createAccountWithBalance(donor);
29 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {26 const proxyContract = new helper.web3!.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {
30 from: owner,27 from: owner,
31 ...GAS_ARGS,28 ...GAS_ARGS,
32 });29 });
35}32}
3633
37describe('Fungible (Via EVM proxy): Information getting', () => {34describe('Fungible (Via EVM proxy): Information getting', () => {
35 let alice: IKeyringPair;
36 let donor: IKeyringPair;
37
38 before(async function() {
39 await usingEthPlaygrounds(async (helper, privateKey) => {
40 donor = privateKey('//Alice');
41 [alice] = await helper.arrange.createAccounts([10n], donor);
42 });
43 });
44
38 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {45 itEth('totalSupply', async ({helper}) => {
39 const collection = await createCollectionExpectSuccess({46 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
40 name: 'token name',
41 mode: {type: 'Fungible', decimalPoints: 0},
42 });
43 const alice = privateKeyWrapper('//Alice');
44 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);47 const caller = await helper.eth.createAccountWithBalance(donor);
45
46 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});48 await collection.mint(alice, 200n, {Substrate: alice.address});
4749
48 const address = collectionIdToAddress(collection);50 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
51 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
49 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);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('200');55 expect(totalSupply).to.equal('200');
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.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
57 name: 'token name',
58 mode: {type: 'Fungible', decimalPoints: 0},
59 });
60 const alice = privateKeyWrapper('//Alice');
61 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);60 const caller = await helper.eth.createAccountWithBalance(donor);
6261
63 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});62 await collection.mint(alice, 200n, {Ethereum: caller});
6463
65 const address = collectionIdToAddress(collection);64 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
65 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
66 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);66 const contract = await proxyWrap(helper, evmCollection, donor);
67 const balance = await contract.methods.balanceOf(caller).call();67 const balance = await contract.methods.balanceOf(caller).call();
6868
69 expect(balance).to.equal('200');69 expect(balance).to.equal('200');
70 });70 });
71});71});
7272
73describe('Fungible (Via EVM proxy): Plain calls', () => {73describe('Fungible (Via EVM proxy): Plain calls', () => {
74 let alice: IKeyringPair;
75 let donor: IKeyringPair;
76
77 before(async function() {
78 await usingEthPlaygrounds(async (helper, privateKey) => {
79 donor = privateKey('//Alice');
80 [alice] = await helper.arrange.createAccounts([10n], donor);
81 });
82 });
83
74 itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {84 itEth('Can perform approve()', async ({helper}) => {
75 const collection = await createCollectionExpectSuccess({85 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
76 name: 'token name',
77 mode: {type: 'Fungible', decimalPoints: 0},
78 });
79 const alice = privateKeyWrapper('//Alice');86 const caller = await helper.eth.createAccountWithBalance(donor);
80 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);87 const spender = helper.eth.createAccount();
88
81 const spender = createEthAccount(web3);89 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
82
83 const address = collectionIdToAddress(collection);90 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
84 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);91 const contract = await proxyWrap(helper, evmCollection, donor);
85 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});92 await collection.mint(alice, 200n, {Ethereum: contract.options.address});
8693
87 {94 {
88 const result = await contract.methods.approve(spender, 100).send({from: caller});95 const result = await contract.methods.approve(spender, 100).send({from: caller});
107 }114 }
108 });115 });
109116
110 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {117 itEth('Can perform transferFrom()', async ({helper}) => {
111 const collection = await createCollectionExpectSuccess({118 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
112 name: 'token name',
113 mode: {type: 'Fungible', decimalPoints: 0},
114 });
115 const alice = privateKeyWrapper('//Alice');
116 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);119 const caller = await helper.eth.createAccountWithBalance(donor);
117 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);120 const owner = await helper.eth.createAccountWithBalance(donor);
118121
119 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});122 await collection.mint(alice, 200n, {Ethereum: owner});
120
121 const receiver = createEthAccount(web3);123 const receiver = helper.eth.createAccount();
122124
123 const address = collectionIdToAddress(collection);125 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
124 const evmCollection = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});126 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
125 const contract = await proxyWrap(api, web3, evmCollection, privateKeyWrapper);127 const contract = await proxyWrap(helper, evmCollection, donor);
126128
127 await evmCollection.methods.approve(contract.options.address, 100).send({from: owner});129 await evmCollection.methods.approve(contract.options.address, 100).send({from: owner});
128130
162 }164 }
163 });165 });
164166
165 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {167 itEth('Can perform transfer()', async ({helper}) => {
166 const collection = await createCollectionExpectSuccess({168 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
167 name: 'token name',
168 mode: {type: 'Fungible', decimalPoints: 0},
169 });
170 const alice = privateKeyWrapper('//Alice');169 const caller = await helper.eth.createAccountWithBalance(donor);
171 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);170 const receiver = await helper.eth.createAccountWithBalance(donor);
171
172 const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);172 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
173
174 const address = collectionIdToAddress(collection);173 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
175 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);174 const contract = await proxyWrap(helper, evmCollection, donor);
176 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});175 await collection.mint(alice, 200n, {Ethereum: contract.options.address});
177176
178 {177 {
179 const result = await contract.methods.transfer(receiver, 50).send({from: caller});178 const result = await contract.methods.transfer(receiver, 50).send({from: caller});