difftreelog
Merge branch 'develop' into tests/feed-alices
in: master
5 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -40,6 +40,7 @@
"testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",
"testEthTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/eth/tokenProperties.test.ts",
+ "testEvmCoder": "mocha --timeout 9999999 -r ts-node/register './**/eth/evmCoder.test.ts'",
"testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
"testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
"testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts ./**/getPropertiesRpc.test.ts",
@@ -68,7 +69,7 @@
"testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",
"testSetPermissions": "mocha --timeout 9999999 -r ts-node/register ./**/setPermissions.test.ts",
"testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",
- "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",
+ "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/eth/contractSponsoring.test.ts",
"testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",
"testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",
"testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",
tests/src/app-promotion.test.tsdiffbeforeafterboth--- a/tests/src/app-promotion.test.ts
+++ b/tests/src/app-promotion.test.ts
@@ -557,6 +557,7 @@
// caller payed for call
expect(1000n * nominal > callerBalance).to.be.true;
+ // todo:playgrounds look into. why did it work before with 1000n, and is now 100n?
expect(contractBalanceAfter).to.be.equal(100n * nominal);
});
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth15// 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 {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import * as solc from 'solc';19import {EthUniqueHelper} from './util/playgrounds/unique.dev';18import {EthUniqueHelper} from './util/playgrounds/unique.dev';20import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from '../eth/util/playgrounds';19import {itEth, expect, SponsoringMode, usingEthPlaygrounds} from '../eth/util/playgrounds';21import {usingPlaygrounds} from '../util/playgrounds';20import {usingPlaygrounds} from '../util/playgrounds';455describe('Sponsoring Fee Limit', () => {454describe('Sponsoring Fee Limit', () => {456 let donor: IKeyringPair;455 let donor: IKeyringPair;457 let alice: IKeyringPair;456 let alice: IKeyringPair;458 let DEFAULT_GAS: number;457 let testContract: CompiledContract;459458460 function compileTestContract() {459 async function compileTestContract(helper: EthUniqueHelper) {461 if (!testContract) {460 if (!testContract) {462 const input = {463 language: 'Solidity',464 sources: {465 ['TestContract.sol']: {466 content:467 `468 // SPDX-License-Identifier: MIT469 pragma solidity ^0.8.0;470 471 contract TestContract {472 event Result(bool);473474 function test(uint32 cycles) public {475 uint256 counter = 0;476 while(true) {477 counter ++;478 if (counter > cycles){479 break;480 }481 }482 emit Result(true);483 }484 }485 `,486 },487 },488 settings: {489 outputSelection: {490 '*': {491 '*': ['*'],492 },493 },494 },495 };496 const json = JSON.parse(solc.compile(JSON.stringify(input)));497 const out = json.contracts['TestContract.sol']['TestContract'];498 499 testContract = {461 testContract = await helper.ethContract.compile(500 abi: out.abi,462 'TestContract',501 object: '0x' + out.evm.bytecode.object,463 `464 // SPDX-License-Identifier: MIT465 pragma solidity ^0.8.0;466 467 contract TestContract {468 event Result(bool);469470 function test(uint32 cycles) public {471 uint256 counter = 0;472 while(true) {473 counter ++;474 if (counter > cycles){475 break;476 }477 }478 emit Result(true);479 }480 }481 `,502 };482 );503 }483 }504 return testContract;484 return testContract;505 }485 }506 486 507 async function deployTestContract(helper: EthUniqueHelper, owner: string) {487 async function deployTestContract(helper: EthUniqueHelper, owner: string) {508 const web3 = helper.getWeb3();509 const compiled = compileTestContract();488 const compiled = await compileTestContract(helper);510 const testContract = new web3.eth.Contract(compiled.abi, undefined, {489 return await helper.ethContract.deployByAbi(owner, compiled.abi, compiled.object);511 data: compiled.object,512 from: owner,513 gas: DEFAULT_GAS,514 });515 return await testContract.deploy({data: compiled.object}).send({from: owner});516 }490 }517491518 before(async () => {492 before(async () => {519 await usingEthPlaygrounds(async (helper, privateKey) => {493 await usingEthPlaygrounds(async (helper, privateKey) => {520 donor = await privateKey({filename: __filename});494 donor = await privateKey({filename: __filename});521 [alice] = await helper.arrange.createAccounts([100n], donor);495 [alice] = await helper.arrange.createAccounts([100n], donor);522 DEFAULT_GAS = helper.eth.DEFAULT_GAS;523 });496 });524 });497 });525526 let testContract: CompiledContract;527498528 itEth('Default fee limit', async ({helper}) => {499 itEth('Default fee limit', async ({helper}) => {529 const owner = await helper.eth.createAccountWithBalance(donor);500 const owner = await helper.eth.createAccountWithBalance(donor);tests/src/eth/evmCoder.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/evmCoder.test.ts
@@ -0,0 +1,90 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// 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 {itEth, expect, usingEthPlaygrounds} from './util/playgrounds';
+
+const getContractSource = (collectionAddress: string, contractAddress: string): string => {
+ return `
+ // SPDX-License-Identifier: MIT
+ pragma solidity ^0.8.0;
+ interface ITest {
+ function ztestzzzzzzz() external returns (uint256 n);
+ }
+ contract Test {
+ event Result(bool, uint256);
+ function test1() public {
+ try
+ ITest(${collectionAddress}).ztestzzzzzzz()
+ returns (uint256 n) {
+ // enters
+ emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]
+ } catch {
+ emit Result(false, 0);
+ }
+ }
+ function test2() public {
+ try
+ ITest(${contractAddress}).ztestzzzzzzz()
+ returns (uint256 n) {
+ emit Result(true, n);
+ } catch {
+ // enters
+ emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]
+ }
+ }
+ function test3() public {
+ ITest(${collectionAddress}).ztestzzzzzzz();
+ }
+ }
+ `;
+};
+
+
+describe('Evm Coder tests', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (_helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ itEth('Call non-existing function', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.eth.createNonfungibleCollection(owner, 'EVMCODER', '', 'TEST');
+ const contract = await helper.ethContract.deployByCode(owner, 'Test', getContractSource(collection.collectionAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c'));
+ const testContract = await helper.ethContract.deployByCode(owner, 'Test', getContractSource(collection.collectionAddress, contract.options.address));
+ {
+ const result = await testContract.methods.test1().send();
+ expect(result.events.Result.returnValues).to.deep.equal({
+ '0': false,
+ '1': '0',
+ });
+ }
+ {
+ const result = await testContract.methods.test2().send();
+ expect(result.events.Result.returnValues).to.deep.equal({
+ '0': false,
+ '1': '0',
+ });
+ }
+ {
+ await expect(testContract.methods.test3().call())
+ .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);
+ }
+ });
+});
tests/src/evmCoder.test.tsdiffbeforeafterboth--- a/tests/src/evmCoder.test.ts
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// 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 Web3 from 'web3';
-import {itEth, expect, usingEthPlaygrounds} from './eth/util/playgrounds';
-import * as solc from 'solc';
-
-async function compileTestContract(collectionAddress: string, contractAddress: string) {
- const input = {
- language: 'Solidity',
- sources: {
- ['Test.sol']: {
- content:
- `
- // SPDX-License-Identifier: MIT
- pragma solidity ^0.8.0;
- interface ITest {
- function ztestzzzzzzz() external returns (uint256 n);
- }
- contract Test {
- event Result(bool, uint256);
- function test1() public {
- try
- ITest(${collectionAddress}).ztestzzzzzzz()
- returns (uint256 n) {
- // enters
- emit Result(true, n); // => [true, BigNumber { value: "43648854190028290368124427828690944273759144372138548774646036134290060795932" }]
- } catch {
- emit Result(false, 0);
- }
- }
- function test2() public {
- try
- ITest(${contractAddress}).ztestzzzzzzz()
- returns (uint256 n) {
- emit Result(true, n);
- } catch {
- // enters
- emit Result(false, 0); // => [ false, BigNumber { value: "0" } ]
- }
- }
- function test3() public {
- ITest(${collectionAddress}).ztestzzzzzzz();
- }
- }
- `,
- },
- },
- settings: {
- outputSelection: {
- '*': {
- '*': ['*'],
- },
- },
- },
- };
- const json = JSON.parse(solc.compile(JSON.stringify(input)));
- const out = json.contracts['Test.sol']['Test'];
-
- return {
- abi: out.abi,
- object: '0x' + out.evm.bytecode.object,
- };
-}
-
-async function deployTestContract(web3: Web3, owner: string, collectionAddress: string, contractAddress: string, gas: number) {
- const compiled = await compileTestContract(collectionAddress, contractAddress);
- const fractionalizerContract = new web3.eth.Contract(compiled.abi, undefined, {
- data: compiled.object,
- from: owner,
- gas,
- });
- return await fractionalizerContract.deploy({data: compiled.object}).send({from: owner});
-}
-
-describe('Evm Coder tests', () => {
- let donor: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (_helper, privateKey) => {
- donor = await privateKey({filename: __filename});
- });
- });
-
- itEth('Call non-existing function', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.eth.createNonfungibleCollection(owner, 'EVMCODER', '', 'TEST');
- const contract = await deployTestContract(helper.getWeb3(), owner, collection.collectionAddress, '0x1bfed5D614b886b9Ab2eA4CBAc22A96B7EC29c9c', helper.eth.DEFAULT_GAS);
- const testContract = await deployTestContract(helper.getWeb3(), owner, collection.collectionAddress, contract.options.address, helper.eth.DEFAULT_GAS);
- {
- const result = await testContract.methods.test1().send();
- expect(result.events.Result.returnValues).to.deep.equal({
- '0': false,
- '1': '0',
- });
- }
- {
- const result = await testContract.methods.test2().send();
- expect(result.events.Result.returnValues).to.deep.equal({
- '0': false,
- '1': '0',
- });
- }
- {
- await expect(testContract.methods.test3().call())
- .to.be.rejectedWith(/unrecognized selector: 0xd9f02b36$/g);
- }
- });
-});