difftreelog
tests: eth_getCode
in: master
5 files changed
tests/src/apiConsts.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import {usingPlaygrounds, itSub, expect, COLLECTION_HELPER, CONTRACT_HELPER} from './util';192021const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;22const MAX_COLLECTION_NAME_LENGTH = 64n;23const COLLECTION_ADMINS_LIMIT = 5n;24const MAX_COLLECTION_PROPERTIES_SIZE = 40960n;25const MAX_TOKEN_PREFIX_LENGTH = 16n;26const MAX_PROPERTY_KEY_LENGTH = 256n;27const MAX_PROPERTY_VALUE_LENGTH = 32768n;28const MAX_PROPERTIES_PER_ITEM = 64n;29const MAX_TOKEN_PROPERTIES_SIZE = 32768n;30const NESTING_BUDGET = 5n;3132const DEFAULT_COLLETCTION_LIMIT = {33 accountTokenOwnershipLimit: '1,000,000',34 sponsoredDataSize: '2,048',35 sponsoredDataRateLimit: 'SponsoringDisabled',36 tokenLimit: '4,294,967,295',37 sponsorTransferTimeout: '5',38 sponsorApproveTimeout: '5',39 ownerCanTransfer: false,40 ownerCanDestroy: true,41 transfersEnabled: true,42};4344describe('integration test: API UNIQUE consts', () => {45 let api: ApiPromise;4647 before(async () => {48 await usingPlaygrounds(async (helper) => {49 api = await helper.getApi();50 });51 });5253 itSub('DEFAULT_NFT_COLLECTION_LIMITS', () => {54 expect(api.consts.unique.nftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);55 });5657 itSub('DEFAULT_RFT_COLLECTION_LIMITS', () => {58 expect(api.consts.unique.rftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);59 });6061 itSub('DEFAULT_FT_COLLECTION_LIMITS', () => {62 expect(api.consts.unique.ftDefaultCollectionLimits.toHuman()).to.deep.equal(DEFAULT_COLLETCTION_LIMIT);63 });6465 itSub('MAX_COLLECTION_NAME_LENGTH', () => {66 checkConst(api.consts.unique.maxCollectionNameLength, MAX_COLLECTION_NAME_LENGTH);67 });6869 itSub('MAX_COLLECTION_DESCRIPTION_LENGTH', () => {70 checkConst(api.consts.unique.maxCollectionDescriptionLength, MAX_COLLECTION_DESCRIPTION_LENGTH);71 });7273 itSub('MAX_COLLECTION_PROPERTIES_SIZE', () => {74 checkConst(api.consts.unique.maxCollectionPropertiesSize, MAX_COLLECTION_PROPERTIES_SIZE);75 });7677 itSub('MAX_TOKEN_PREFIX_LENGTH', () => {78 checkConst(api.consts.unique.maxTokenPrefixLength, MAX_TOKEN_PREFIX_LENGTH);79 });8081 itSub('MAX_PROPERTY_KEY_LENGTH', () => {82 checkConst(api.consts.unique.maxPropertyKeyLength, MAX_PROPERTY_KEY_LENGTH);83 });8485 itSub('MAX_PROPERTY_VALUE_LENGTH', () => {86 checkConst(api.consts.unique.maxPropertyValueLength, MAX_PROPERTY_VALUE_LENGTH);87 });8889 itSub('MAX_PROPERTIES_PER_ITEM', () => {90 checkConst(api.consts.unique.maxPropertiesPerItem, MAX_PROPERTIES_PER_ITEM);91 });9293 itSub('NESTING_BUDGET', () => {94 checkConst(api.consts.unique.nestingBudget, NESTING_BUDGET);95 });9697 itSub('MAX_TOKEN_PROPERTIES_SIZE', () => {98 checkConst(api.consts.unique.maxTokenPropertiesSize, MAX_TOKEN_PROPERTIES_SIZE);99 });100101 itSub('COLLECTION_ADMINS_LIMIT', () => {102 checkConst(api.consts.unique.collectionAdminsLimit, COLLECTION_ADMINS_LIMIT);103 });104105 itSub('HELPERS_CONTRACT_ADDRESS', () => {106 expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(CONTRACT_HELPER.toLowerCase());107 });108109 itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {110 expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(COLLECTION_HELPER.toLowerCase());111 });112});113114function checkConst<T>(constValue: any, expectedValue: T) {115 expect(constValue.toBigInt()).equal(expectedValue);116}tests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionHelperAddress.test.ts
+++ b/tests/src/eth/collectionHelperAddress.test.ts
@@ -16,9 +16,7 @@
import {itEth, usingEthPlaygrounds, expect} from './util';
import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets} from '../util';
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+import {COLLECTION_HELPER, Pallets} from '../util';
describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {
let donor: IKeyringPair;
@@ -36,7 +34,7 @@
const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);
expect((await nftCollection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {
@@ -46,7 +44,7 @@
const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
expect((await rftCollection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth('FT', async ({helper}) => {
@@ -56,7 +54,7 @@
const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
expect((await collection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -18,6 +18,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {expect, itEth, usingEthPlaygrounds} from './util';
import {CollectionLimitField} from './util/playgrounds/types';
+import {COLLECTION_HELPER} from '../util';
describe('Create NFT collection from EVM', () => {
@@ -42,7 +43,7 @@
expect(events).to.be.deep.equal([
{
- address: '0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F',
+ address: COLLECTION_HELPER,
event: 'CollectionCreated',
args: {
owner: owner,
tests/src/eth/getCode.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/getCode.test.ts
@@ -0,0 +1,53 @@
+// 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 {expect, itEth, usingEthPlaygrounds} from './util';
+import {IKeyringPair} from '@polkadot/types/types';
+import {COLLECTION_HELPER, CONTRACT_HELPER} from '../util';
+
+describe('RPC eth_getCode', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ [
+ {address: COLLECTION_HELPER, expectedCode: '0x60e0604052602660808181529061073160a03960019061001f90826100d1565b5034801561002c57600080fd5b50610190565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061005c57607f821691505b60208210810361007c57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156100cc57600081815260208120601f850160051c810160208610156100a95750805b601f850160051c820191505b818110156100c8578281556001016100b5565b5050505b505050565b81516001600160401b038111156100ea576100ea610032565b6100fe816100f88454610048565b84610082565b602080601f831160018114610133576000841561011b5750858301515b600019600386901b1c1916600185901b1785556100c8565b600085815260208120601f198616915b8281101561016257888601518255948401946001909101908401610143565b50858210156101805787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6105928061019f6000396000f3fe6080604052600436106100915760003560e01c80638562425811610059578063856242581461013c578063ab1734501461012e578063b5cb749814610157578063c3de149414610187578063d23a7ab1146101a257600080fd5b806301ffc9a7146100965780632e716683146100cb578063564e321f146100fe5780637335b79f14610120578063844af6581461012e575b600080fd5b3480156100a257600080fd5b506100b66100b1366004610206565b6101c5565b60405190151581526020015b60405180910390f35b3480156100d757600080fd5b506100e66100b1366004610237565b6040516001600160a01b0390911681526020016100c2565b34801561010a57600080fd5b5061011e610119366004610279565b6101eb565b005b6100e66100b1366004610337565b6100e66100b13660046103da565b34801561014857600080fd5b5061011e610119366004610462565b34801561016357600080fd5b506101726100b1366004610279565b60405163ffffffff90911681526020016100c2565b34801561019357600080fd5b506100b66100b1366004610279565b3480156101ae57600080fd5b506101b76101c5565b6040519081526020016100c2565b6000600160405162461bcd60e51b81526004016101e291906104b0565b60405180910390fd5b600160405162461bcd60e51b81526004016101e291906104b0565b60006020828403121561021857600080fd5b81356001600160e01b03198116811461023057600080fd5b9392505050565b60006020828403121561024957600080fd5b813563ffffffff8116811461023057600080fd5b80356001600160a01b038116811461027457600080fd5b919050565b60006020828403121561028b57600080fd5b6102308261025d565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126102bb57600080fd5b813567ffffffffffffffff808211156102d6576102d6610294565b604051601f8301601f19908116603f011681019082821181831017156102fe576102fe610294565b8160405283815286602085880101111561031757600080fd5b836020870160208301376000602085830101528094505050505092915050565b6000806000806080858703121561034d57600080fd5b843567ffffffffffffffff8082111561036557600080fd5b610371888389016102aa565b95506020870135915060ff8216821461038957600080fd5b9093506040860135908082111561039f57600080fd5b6103ab888389016102aa565b935060608701359150808211156103c157600080fd5b506103ce878288016102aa565b91505092959194509250565b6000806000606084860312156103ef57600080fd5b833567ffffffffffffffff8082111561040757600080fd5b610413878388016102aa565b9450602086013591508082111561042957600080fd5b610435878388016102aa565b9350604086013591508082111561044b57600080fd5b50610458868287016102aa565b9150509250925092565b6000806040838503121561047557600080fd5b61047e8361025d565b9150602083013567ffffffffffffffff81111561049a57600080fd5b6104a6858286016102aa565b9150509250929050565b600060208083526000845481600182811c9150808316806104d257607f831692505b85831081036104ef57634e487b7160e01b85526022600452602485fd5b87860183815260200181801561050c57600181146105225761054d565b60ff198616825284151560051b8201965061054d565b60008b81526020902060005b868110156105475781548482015290850190890161052e565b83019750505b5094999850505050505050505056fea2646970667358221220a43ca09fe677b7ab611be4b7ea2ed7e656ade53b3d1252c653ff4a84b36d3c3064736f6c634300081000337468697320636f6e747261637420697320696d706c656d656e74656420696e206e6174697665'},
+ {address: CONTRACT_HELPER, expectedCode: '0x60e0604052602660808181529061073060a03960019061001f90826100d1565b5034801561002c57600080fd5b50610190565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061005c57607f821691505b60208210810361007c57634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156100cc57600081815260208120601f850160051c810160208610156100a95750805b601f850160051c820191505b818110156100c8578281556001016100b5565b5050505b505050565b81516001600160401b038111156100ea576100ea610032565b6100fe816100f88454610048565b84610082565b602080601f831160018114610133576000841561011b5750858301515b600019600386901b1c1916600185901b1785556100c8565b600085815260208120601f198616915b8281101561016257888601518255948401946001909101908401610143565b50858210156101805787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6105918061019f6000396000f3fe608060405234801561001057600080fd5b50600436106101215760003560e01c8063766c4f37116100ad578063c772ef6c11610071578063c772ef6c14610171578063ef7842501461022d578063f01fba931461023b578063f29694d814610249578063fde8a5601461026c57600080fd5b8063766c4f37146101dd57806377b6c9081461021f57806389f7d9ae1461022d5780639741860314610171578063abc000011461022d57600080fd5b80634706cc1c116100f45780634706cc1c1461017f5780635152b14c1461018d5780635c658165146101b35780636027dc611461017157806375b73606146101c157600080fd5b806301ffc9a71461012657806303aed6651461014e57806336de20f51461016357806339b9b24214610171575b600080fd5b6101396101343660046102fd565b61027a565b60405190151581526020015b60405180910390f35b61016161015c36600461034a565b6102a0565b005b61016161015c366004610384565b6101396101343660046103b7565b61016161015c3660046103d2565b61019b6101343660046103b7565b6040516001600160a01b039091168152602001610145565b610139610134366004610415565b6101cf6101343660046103b7565b604051908152602001610145565b6101f06101eb3660046103b7565b6102bb565b6040805182511515815260209283015180516001600160a01b0316848301529092015190820152606001610145565b61016161015c36600461043f565b61016161015c3660046103b7565b61016161015c366004610415565b6102576101343660046103b7565b60405163ffffffff9091168152602001610145565b61016161015c36600461047f565b6000600160405162461bcd60e51b815260040161029791906104af565b60405180910390fd5b600160405162461bcd60e51b815260040161029791906104af565b6102a060405180604001604052806000151581526020016102f8604051806040016040528060006001600160a01b03168152602001600081525090565b905290565b60006020828403121561030f57600080fd5b81356001600160e01b03198116811461032757600080fd5b9392505050565b80356001600160a01b038116811461034557600080fd5b919050565b6000806040838503121561035d57600080fd5b6103668361032e565b946020939093013593505050565b8035801515811461034557600080fd5b6000806040838503121561039757600080fd5b6103a08361032e565b91506103ae60208401610374565b90509250929050565b6000602082840312156103c957600080fd5b6103278261032e565b6000806000606084860312156103e757600080fd5b6103f08461032e565b92506103fe6020850161032e565b915061040c60408501610374565b90509250925092565b6000806040838503121561042857600080fd5b6104318361032e565b91506103ae6020840161032e565b6000806040838503121561045257600080fd5b61045b8361032e565b9150602083013563ffffffff8116811461047457600080fd5b809150509250929050565b6000806040838503121561049257600080fd5b61049b8361032e565b915060208301356003811061047457600080fd5b600060208083526000845481600182811c9150808316806104d157607f831692505b85831081036104ee57634e487b7160e01b85526022600452602485fd5b87860183815260200181801561050b57600181146105215761054c565b60ff198616825284151560051b8201965061054c565b60008b81526020902060005b868110156105465781548482015290850190890161052d565b83019750505b5094999850505050505050505056fea264697066735822122063505542f1c4602234fba58885c20aae30258ff8096b7f974a5563c90ad4a6c464736f6c634300081000337468697320636f6e747261637420697320696d706c656d656e74656420696e206e6174697665'},
+ ].map(testCase => {
+ itEth(`returns value for native contract: ${testCase.address}`, async ({helper}) => {
+ const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [testCase.address])).toJSON();
+ const contractCodeEth = (await helper.getWeb3().eth.getCode(testCase.address));
+
+ expect(contractCodeSub).to.eq(testCase.expectedCode);
+ expect(contractCodeEth).to.eq(testCase.expectedCode);
+ });
+ });
+
+ itEth('returns value for custom contract', async ({helper}) => {
+ const signer = await helper.eth.createAccountWithBalance(donor);
+ const flipper = await helper.eth.deployFlipper(signer);
+
+ const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [flipper.options.address])).toJSON();
+ const contractCodeEth = (await helper.getWeb3().eth.getCode(flipper.options.address));
+
+ expect(contractCodeSub).to.eq('0x6080604052348015600f57600080fd5b506004361060325760003560e01c806320965255146037578063cde4efa9146051575b600080fd5b603d6059565b6040516048919060b1565b60405180910390f35b6057606f565b005b60008060009054906101000a900460ff16905090565b60008054906101000a900460ff16156000806101000a81548160ff021916908315150217905550565b60008115159050919050565b60ab816098565b82525050565b600060208201905060c4600083018460a4565b9291505056fea264697066735822122077b6e0181f948cf0762391122339dd11290f54d8fd71596e8fe216ba8577e9f164736f6c63430008110033');
+ expect(contractCodeEth).to.eq('0x6080604052348015600f57600080fd5b506004361060325760003560e01c806320965255146037578063cde4efa9146051575b600080fd5b603d6059565b6040516048919060b1565b60405180910390f35b6057606f565b005b60008060009054906101000a900460ff16905090565b60008054906101000a900460ff16156000806101000a81548160ff021916908315150217905550565b60008115159050919050565b60ab816098565b82525050565b600060208201905060c4600083018460a4565b9291505056fea264697066735822122077b6e0181f948cf0762391122339dd11290f54d8fd71596e8fe216ba8577e9f164736f6c63430008110033');
+ });
+});
tests/src/util/index.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -100,6 +100,9 @@
export const LOCKING_PERIOD = 12n; // 12 blocks of relay
export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain
+// Native contracts
+export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
export enum Pallets {
Inflation = 'inflation',