difftreelog
added tests for `createRTCollection` , refactor `Unique` pallet code
in: master
9 files changed
pallets/unique/CHANGELOG.mddiffbeforeafterboth--- a/pallets/unique/CHANGELOG.md
+++ b/pallets/unique/CHANGELOG.md
@@ -8,7 +8,7 @@
### Changes
-- Addded **CollectionHelpers** method `destroyCollection`.
+- Added `destroyCollection` and `createFTCollection` methods to **CollectionHelpers**.
## [v0.2.0] 2022-09-13
pallets/unique/src/eth/mod.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/mod.rs
+++ b/pallets/unique/src/eth/mod.rs
@@ -18,7 +18,7 @@
use core::marker::PhantomData;
use ethereum as _;
-use evm_coder::{execution::*, generate_stubgen, solidity_interface, solidity, weight, types::*};
+use evm_coder::{execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight};
use frame_support::traits::Get;
use crate::Pallet;
@@ -27,23 +27,24 @@
CollectionById,
dispatch::CollectionDispatch,
erc::{
+ static_property::key,
CollectionHelpersEvents,
- static_property::{key},
},
Pallet as PalletCommon,
+
};
+use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
use pallet_evm_coder_substrate::{dispatch_to_evm, SubstrateRecorder, WithRecorder};
-use pallet_evm::{account::CrossAccountId, OnMethodCall, PrecompileHandle, PrecompileResult};
use sp_std::vec;
use up_data_structs::{
- CollectionName, CollectionDescription, CollectionTokenPrefix, CreateCollectionData,
- CollectionMode, PropertyValue,
+ CollectionDescription, CollectionMode, CollectionName, CollectionTokenPrefix,
+ CreateCollectionData, PropertyValue,
};
-use crate::{Config, SelfWeightOf, weights::WeightInfo};
+use crate::{weights::WeightInfo, Config, SelfWeightOf};
-use sp_std::vec::Vec;
use alloc::format;
+use sp_std::vec::Vec;
/// See [`CollectionHelpersCall`]
pub struct EvmCollectionHelpers<T: Config>(SubstrateRecorder<T>);
@@ -104,6 +105,7 @@
)
}
+#[inline(always)]
fn create_collection_internal<T: Config>(
caller: caller,
value: value,
@@ -212,7 +214,14 @@
description: string,
token_prefix: string,
) -> Result<address> {
- self.create_nft_collection(caller, value, name, description, token_prefix)
+ create_collection_internal::<T>(
+ caller,
+ value,
+ name,
+ CollectionMode::NFT,
+ description,
+ token_prefix,
+ )
}
#[weight(<SelfWeightOf<T>>::create_collection())]
@@ -225,11 +234,39 @@
description: string,
token_prefix: string,
) -> Result<address> {
- create_refungible_collection_internal::<T>(caller, value, name, description, token_prefix)
+ create_collection_internal::<T>(
+ caller,
+ value,
+ name,
+ CollectionMode::ReFungible,
+ description,
+ token_prefix,
+ )
+ }
+
+ #[weight(<SelfWeightOf<T>>::create_collection())]
+ #[solidity(rename_selector = "createERC721MetadataCompatibleRFTCollection")]
+ fn create_refungible_collection_with_properties(
+ &mut self,
+ caller: caller,
+ value: value,
+ name: string,
+ description: string,
+ token_prefix: string,
+ base_uri: string,
+ ) -> Result<address> {
+ create_collection_internal::<T>(
+ caller,
+ value,
+ name,
+ CollectionMode::ReFungible,
+ description,
+ token_prefix,
+ )
}
#[weight(<SelfWeightOf<T>>::create_collection())]
- #[solidity(rename_selector = "createRTCollection")]
+ #[solidity(rename_selector = "createFTCollection")]
fn create_fungible_collection(
&mut self,
caller: caller,
pallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/unique/src/eth/stubs/CollectionHelpers.soldiffbeforeafterboth--- a/pallets/unique/src/eth/stubs/CollectionHelpers.sol
+++ b/pallets/unique/src/eth/stubs/CollectionHelpers.sol
@@ -24,7 +24,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0xa2c196ab
+/// @dev the ERC-165 identifier for this interface is 0xd8b36039
contract CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -77,9 +77,26 @@
return 0x0000000000000000000000000000000000000000;
}
- /// @dev EVM selector for this function is: 0xac1e2285,
- /// or in textual repr: createRTCollection(string,uint8,string,string)
- function createRTCollection(
+ /// @dev EVM selector for this function is: 0xa5596388,
+ /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
+ function createERC721MetadataCompatibleRFTCollection(
+ string memory name,
+ string memory description,
+ string memory tokenPrefix,
+ string memory baseUri
+ ) public payable returns (address) {
+ require(false, stub_error);
+ name;
+ description;
+ tokenPrefix;
+ baseUri;
+ dummy = 0;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
+ /// @dev EVM selector for this function is: 0x7335b79f,
+ /// or in textual repr: createFTCollection(string,uint8,string,string)
+ function createFTCollection(
string memory name,
uint8 decimals,
string memory description,
tests/src/eth/api/CollectionHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/CollectionHelpers.sol
+++ b/tests/src/eth/api/CollectionHelpers.sol
@@ -19,7 +19,7 @@
}
/// @title Contract, which allows users to operate with collections
-/// @dev the ERC-165 identifier for this interface is 0xa2c196ab
+/// @dev the ERC-165 identifier for this interface is 0xd8b36039
interface CollectionHelpers is Dummy, ERC165, CollectionHelpersEvents {
/// Create an NFT collection
/// @param name Name of the collection
@@ -51,9 +51,18 @@
string memory tokenPrefix
) external payable returns (address);
- /// @dev EVM selector for this function is: 0xac1e2285,
- /// or in textual repr: createRTCollection(string,uint8,string,string)
- function createRTCollection(
+ /// @dev EVM selector for this function is: 0xa5596388,
+ /// or in textual repr: createERC721MetadataCompatibleRFTCollection(string,string,string,string)
+ function createERC721MetadataCompatibleRFTCollection(
+ string memory name,
+ string memory description,
+ string memory tokenPrefix,
+ string memory baseUri
+ ) external payable returns (address);
+
+ /// @dev EVM selector for this function is: 0x7335b79f,
+ /// or in textual repr: createFTCollection(string,uint8,string,string)
+ function createFTCollection(
string memory name,
uint8 decimals,
string memory description,
tests/src/eth/collectionHelpersAbi.jsondiffbeforeafterboth--- a/tests/src/eth/collectionHelpersAbi.json
+++ b/tests/src/eth/collectionHelpersAbi.json
@@ -42,9 +42,22 @@
"inputs": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "string", "name": "description", "type": "string" },
+ { "internalType": "string", "name": "tokenPrefix", "type": "string" },
+ { "internalType": "string", "name": "baseUri", "type": "string" }
+ ],
+ "name": "createERC721MetadataCompatibleRFTCollection",
+ "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
+ "stateMutability": "payable",
+ "type": "function"
+ },
+ {
+ "inputs": [
+ { "internalType": "string", "name": "name", "type": "string" },
+ { "internalType": "uint8", "name": "decimals", "type": "uint8" },
+ { "internalType": "string", "name": "description", "type": "string" },
{ "internalType": "string", "name": "tokenPrefix", "type": "string" }
],
- "name": "createNFTCollection",
+ "name": "createFTCollection",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "payable",
"type": "function"
@@ -55,7 +68,7 @@
{ "internalType": "string", "name": "description", "type": "string" },
{ "internalType": "string", "name": "tokenPrefix", "type": "string" }
],
- "name": "createRFTCollection",
+ "name": "createNFTCollection",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "payable",
"type": "function"
@@ -63,11 +76,10 @@
{
"inputs": [
{ "internalType": "string", "name": "name", "type": "string" },
- { "internalType": "uint8", "name": "decimals", "type": "uint8" },
{ "internalType": "string", "name": "description", "type": "string" },
{ "internalType": "string", "name": "tokenPrefix", "type": "string" }
],
- "name": "createRTCollection",
+ "name": "createRFTCollection",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "payable",
"type": "function"
tests/src/eth/createFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createFTCollection.test.ts
+++ b/tests/src/eth/createFTCollection.test.ts
@@ -15,6 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
+import { evmToAddress } from '@polkadot/util-crypto';
import {Pallets, requirePalletsOrSkip} from '../util';
import {expect, itEth, usingEthPlaygrounds} from './util';
@@ -25,7 +26,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ requirePalletsOrSkip(this, helper, [Pallets.Fungible]);
donor = await privateKey('//Alice');
});
});
@@ -39,15 +40,10 @@
// todo:playgrounds this might fail when in async environment.
const collectionCountBefore = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
+
+ const {collectionId} = await helper.eth.createFungibleCollection(owner, name, DECIMALS, description, prefix);
- const collectionCreationPrice = helper.balance.getCollectionCreationPrice();
- const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
-
- const result = await collectionHelper.methods.createRTCollection(name, DECIMALS, description, prefix).call({value: Number(collectionCreationPrice)});
- console.log(result);
- const {collectionId} = await helper.eth.createFungibleCollection(owner, name, DECIMALS, description, prefix);
const collectionCountAfter = +(await helper.callRpc('api.rpc.unique.collectionStats')).created;
-
const data = (await helper.ft.getData(collectionId))!;
expect(collectionCountAfter - collectionCountBefore).to.be.eq(1);
@@ -58,197 +54,209 @@
expect(data.raw.mode).to.be.deep.eq({Fungible: DECIMALS.toString()});
});
- // // todo:playgrounds this test will fail when in async environment.
- // itEth('Check collection address exist', async ({helper}) => {
- // const owner = await helper.eth.createAccountWithBalance(donor);
+ // todo:playgrounds this test will fail when in async environment.
+ itEth('Check collection address exist', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
- // const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
- // const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);
- // const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
+ const expectedCollectionId = +(await helper.callRpc('api.rpc.unique.collectionStats')).created + 1;
+ const expectedCollectionAddress = helper.ethAddress.fromCollectionId(expectedCollectionId);
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
+
+ expect(await collectionHelpers.methods
+ .isCollectionExist(expectedCollectionAddress)
+ .call()).to.be.false;
- // expect(await collectionHelpers.methods
- // .isCollectionExist(expectedCollectionAddress)
- // .call()).to.be.false;
+
+ await helper.eth.createFungibleCollection(owner, 'A', DECIMALS, 'A', 'A');
- // await collectionHelpers.methods
- // .createRFTCollection('A', 'A', 'A')
- // .send({value: Number(2n * helper.balance.getOneTokenNominal())});
- // expect(await collectionHelpers.methods
- // .isCollectionExist(expectedCollectionAddress)
- // .call()).to.be.true;
- // });
+ expect(await collectionHelpers.methods
+ .isCollectionExist(expectedCollectionAddress)
+ .call()).to.be.true;
+ });
- // itEth('Set sponsorship', async ({helper}) => {
- // const owner = await helper.eth.createAccountWithBalance(donor);
- // const sponsor = await helper.eth.createAccountWithBalance(donor);
- // const ss58Format = helper.chain.getChainProperties().ss58Format;
- // const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sponsor', 'absolutely anything', 'ENVY');
+ itEth('Set sponsorship', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ const ss58Format = helper.chain.getChainProperties().ss58Format;
+ const {collectionId, collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Sponsor', DECIMALS, 'absolutely anything', 'ENVY');
- // const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
- // await collection.methods.setCollectionSponsor(sponsor).send();
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+ await collection.methods.setCollectionSponsor(sponsor).send();
- // let data = (await helper.rft.getData(collectionId))!;
- // expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
+ let data = (await helper.rft.getData(collectionId))!;
+ expect(data.raw.sponsorship.Unconfirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- // await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
+ await expect(collection.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
- // const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
- // await sponsorCollection.methods.confirmCollectionSponsorship().send();
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
+ await sponsorCollection.methods.confirmCollectionSponsorship().send();
- // data = (await helper.rft.getData(collectionId))!;
- // expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
- // });
+ data = (await helper.rft.getData(collectionId))!;
+ expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
+ });
+
+ itEth('Set limits', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const {collectionId, collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'INSI');
+ const limits = {
+ accountTokenOwnershipLimit: 1000,
+ sponsoredDataSize: 1024,
+ sponsoredDataRateLimit: 30,
+ tokenLimit: 1000000,
+ sponsorTransferTimeout: 6,
+ sponsorApproveTimeout: 6,
+ ownerCanTransfer: false,
+ ownerCanDestroy: false,
+ transfersEnabled: false,
+ };
- // itEth('Set limits', async ({helper}) => {
- // const owner = await helper.eth.createAccountWithBalance(donor);
- // const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'INSI');
- // const limits = {
- // accountTokenOwnershipLimit: 1000,
- // sponsoredDataSize: 1024,
- // sponsoredDataRateLimit: 30,
- // tokenLimit: 1000000,
- // sponsorTransferTimeout: 6,
- // sponsorApproveTimeout: 6,
- // ownerCanTransfer: false,
- // ownerCanDestroy: false,
- // transfersEnabled: false,
- // };
+ const collection = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+ await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
+ await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();
+ await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
+ await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();
+ await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
+ await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
+ await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();
+ await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();
+ await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();
+
+ const data = (await helper.rft.getData(collectionId))!;
+ expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);
+ expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);
+ expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);
+ expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);
+ expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);
+ expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);
+ expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);
+ expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);
+ expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);
+ });
- // const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
- // await collection.methods['setCollectionLimit(string,uint32)']('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
- // await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataSize', limits.sponsoredDataSize).send();
- // await collection.methods['setCollectionLimit(string,uint32)']('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
- // await collection.methods['setCollectionLimit(string,uint32)']('tokenLimit', limits.tokenLimit).send();
- // await collection.methods['setCollectionLimit(string,uint32)']('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
- // await collection.methods['setCollectionLimit(string,uint32)']('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
- // await collection.methods['setCollectionLimit(string,bool)']('ownerCanTransfer', limits.ownerCanTransfer).send();
- // await collection.methods['setCollectionLimit(string,bool)']('ownerCanDestroy', limits.ownerCanDestroy).send();
- // await collection.methods['setCollectionLimit(string,bool)']('transfersEnabled', limits.transfersEnabled).send();
+ itEth('Collection address exist', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
+ expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)
+ .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
+ .to.be.false;
- // const data = (await helper.rft.getData(collectionId))!;
- // expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(limits.accountTokenOwnershipLimit);
- // expect(data.raw.limits.sponsoredDataSize).to.be.eq(limits.sponsoredDataSize);
- // expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(limits.sponsoredDataRateLimit);
- // expect(data.raw.limits.tokenLimit).to.be.eq(limits.tokenLimit);
- // expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(limits.sponsorTransferTimeout);
- // expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(limits.sponsorApproveTimeout);
- // expect(data.raw.limits.ownerCanTransfer).to.be.eq(limits.ownerCanTransfer);
- // expect(data.raw.limits.ownerCanDestroy).to.be.eq(limits.ownerCanDestroy);
- // expect(data.raw.limits.transfersEnabled).to.be.eq(limits.transfersEnabled);
- // });
+ const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
+ expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)
+ .methods.isCollectionExist(collectionAddress).call())
+ .to.be.true;
+ });
+
+ itEth('destroyCollection', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- // itEth('Collection address exist', async ({helper}) => {
- // const owner = await helper.eth.createAccountWithBalance(donor);
- // const collectionAddressForNonexistentCollection = '0x17C4E6453CC49AAAAEACA894E6D9683E00112233';
- // expect(await helper.ethNativeContract.collectionHelpers(collectionAddressForNonexistentCollection)
- // .methods.isCollectionExist(collectionAddressForNonexistentCollection).call())
- // .to.be.false;
+ const result = await collectionHelper.methods
+ .destroyCollection(collectionAddress)
+ .send({from: owner});
+
+ const events = helper.eth.normalizeEvents(result.events);
- // const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Exister', 'absolutely anything', 'WIWT');
- // expect(await helper.ethNativeContract.collectionHelpers(collectionAddress)
- // .methods.isCollectionExist(collectionAddress).call())
- // .to.be.true;
- // });
+ expect(events).to.be.deep.equal([
+ {
+ address: collectionHelper.options.address,
+ event: 'CollectionDestroyed',
+ args: {
+ collectionId: collectionAddress,
+ },
+ },
+ ]);
+
+ expect(await collectionHelper.methods
+ .isCollectionExist(collectionAddress)
+ .call()).to.be.false;
+ });
});
-// describe('(!negative tests!) Create RFT collection from EVM', () => {
-// let donor: IKeyringPair;
-// let nominal: bigint;
+describe('(!negative tests!) Create FT collection from EVM', () => {
+ let donor: IKeyringPair;
+ let nominal: bigint;
-// before(async function() {
-// await usingEthPlaygrounds(async (helper, privateKey) => {
-// requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-// donor = privateKey('//Alice');
-// nominal = helper.balance.getOneTokenNominal();
-// });
-// });
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.Fungible]);
+ donor = await privateKey('//Alice');
+ nominal = helper.balance.getOneTokenNominal();
+ });
+ });
-// itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
-// const owner = await helper.eth.createAccountWithBalance(donor);
-// const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
-// {
-// const MAX_NAME_LENGTH = 64;
-// const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
-// const description = 'A';
-// const tokenPrefix = 'A';
+ itEth('(!negative test!) Create collection (bad lengths)', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ {
+ const MAX_NAME_LENGTH = 64;
+ const collectionName = 'A'.repeat(MAX_NAME_LENGTH + 1);
+ const description = 'A';
+ const tokenPrefix = 'A';
-// await expect(collectionHelper.methods
-// .createRFTCollection(collectionName, description, tokenPrefix)
-// .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
-// }
-// {
-// const MAX_DESCRIPTION_LENGTH = 256;
-// const collectionName = 'A';
-// const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);
-// const tokenPrefix = 'A';
-// await expect(collectionHelper.methods
-// .createRFTCollection(collectionName, description, tokenPrefix)
-// .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
-// }
-// {
-// const MAX_TOKEN_PREFIX_LENGTH = 16;
-// const collectionName = 'A';
-// const description = 'A';
-// const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
-// await expect(collectionHelper.methods
-// .createRFTCollection(collectionName, description, tokenPrefix)
-// .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
-// }
-// });
+ await expect(collectionHelper.methods
+ .createFTCollection(collectionName, DECIMALS, description, tokenPrefix)
+ .call({value: Number(2n * nominal)})).to.be.rejectedWith('name is too long. Max length is ' + MAX_NAME_LENGTH);
+ }
+ {
+ const MAX_DESCRIPTION_LENGTH = 256;
+ const collectionName = 'A';
+ const description = 'A'.repeat(MAX_DESCRIPTION_LENGTH + 1);
+ const tokenPrefix = 'A';
+ await expect(collectionHelper.methods
+ .createFTCollection(collectionName, DECIMALS, description, tokenPrefix)
+ .call({value: Number(2n * nominal)})).to.be.rejectedWith('description is too long. Max length is ' + MAX_DESCRIPTION_LENGTH);
+ }
+ {
+ const MAX_TOKEN_PREFIX_LENGTH = 16;
+ const collectionName = 'A';
+ const description = 'A';
+ const tokenPrefix = 'A'.repeat(MAX_TOKEN_PREFIX_LENGTH + 1);
+ await expect(collectionHelper.methods
+ .createFTCollection(collectionName, DECIMALS, description, tokenPrefix)
+ .call({value: Number(2n * nominal)})).to.be.rejectedWith('token_prefix is too long. Max length is ' + MAX_TOKEN_PREFIX_LENGTH);
+ }
+ });
-// itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
-// const owner = await helper.eth.createAccountWithBalance(donor);
-// const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
-// await expect(collectionHelper.methods
-// .createRFTCollection('Peasantry', 'absolutely anything', 'TWIW')
-// .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
-// });
+ itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ await expect(collectionHelper.methods
+ .createFTCollection('Peasantry', DECIMALS, 'absolutely anything', 'TWIW')
+ .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
+ });
-// itEth('(!negative test!) Check owner', async ({helper}) => {
-// const owner = await helper.eth.createAccountWithBalance(donor);
-// const peasant = helper.eth.createAccount();
-// const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Transgressed', 'absolutely anything', 'YVNE');
-// const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', peasant);
-// const EXPECTED_ERROR = 'NoPermission';
-// {
-// const sponsor = await helper.eth.createAccountWithBalance(donor);
-// await expect(peasantCollection.methods
-// .setCollectionSponsor(sponsor)
-// .call()).to.be.rejectedWith(EXPECTED_ERROR);
+ itEth('(!negative test!) Check owner', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const peasant = helper.eth.createAccount();
+ const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Transgressed', DECIMALS, 'absolutely anything', 'YVNE');
+ const peasantCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', peasant);
+ const EXPECTED_ERROR = 'NoPermission';
+ {
+ const sponsor = await helper.eth.createAccountWithBalance(donor);
+ await expect(peasantCollection.methods
+ .setCollectionSponsor(sponsor)
+ .call()).to.be.rejectedWith(EXPECTED_ERROR);
-// const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'rft', sponsor);
-// await expect(sponsorCollection.methods
-// .confirmCollectionSponsorship()
-// .call()).to.be.rejectedWith('caller is not set as sponsor');
-// }
-// {
-// await expect(peasantCollection.methods
-// .setCollectionLimit('account_token_ownership_limit', '1000')
-// .call()).to.be.rejectedWith(EXPECTED_ERROR);
-// }
-// });
+ const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'ft', sponsor);
+ await expect(sponsorCollection.methods
+ .confirmCollectionSponsorship()
+ .call()).to.be.rejectedWith('caller is not set as sponsor');
+ }
+ {
+ await expect(peasantCollection.methods
+ .setCollectionLimit('account_token_ownership_limit', '1000')
+ .call()).to.be.rejectedWith(EXPECTED_ERROR);
+ }
+ });
-// itEth('(!negative test!) Set limits', async ({helper}) => {
-// const owner = await helper.eth.createAccountWithBalance(donor);
-// const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'ISNI');
-// const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
-// await expect(collectionEvm.methods
-// .setCollectionLimit('badLimit', 'true')
-// .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');
-// });
-
-// itEth('destroyCollection test', async ({helper}) => {
-// const owner = await helper.eth.createAccountWithBalance(donor);
-// const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Limits', 'absolutely anything', 'OLF');
-// const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
-
-// await expect(collectionHelper.methods
-// .destroyCollection(collectionAddress)
-// .send({from: owner})).to.be.fulfilled;
-
-// expect(await collectionHelper.methods
-// .isCollectionExist(collectionAddress)
-// .call()).to.be.false;
-// });
-// });
+ itEth('(!negative test!) Set limits', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'ISNI');
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+ await expect(collectionEvm.methods
+ .setCollectionLimit('badLimit', 'true')
+ .call()).to.be.rejectedWith('unknown boolean limit "badLimit"');
+ });
+});
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -264,7 +264,7 @@
.call()).to.be.rejectedWith('unknown boolean limit "badLimit"');
});
- itEth('destroyCollection test', async ({helper}) => {
+ itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034/* eslint-disable function-call-argument-newline */5// eslint-disable-next-line @typescript-eslint/triple-slash-reference6/// <reference path="unique.dev.d.ts" />78import {readFile} from 'fs/promises';910import Web3 from 'web3';11import {WebsocketProvider} from 'web3-core';12import {Contract} from 'web3-eth-contract';1314import * as solc from 'solc';1516import {evmToAddress} from '@polkadot/util-crypto';17import {IKeyringPair} from '@polkadot/types/types';1819import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';2021import {ContractImports, CompiledContract, TEthCrossAccount, NormalizedEvent, EthProperty} from './types';2223// Native contracts ABI24import collectionHelpersAbi from '../../collectionHelpersAbi.json';25import fungibleAbi from '../../fungibleAbi.json';26import nonFungibleAbi from '../../nonFungibleAbi.json';27import refungibleAbi from '../../reFungibleAbi.json';28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';29import contractHelpersAbi from './../contractHelpersAbi.json';30import {ICrossAccountId, TEthereumAccount} from '../../../util/playgrounds/types';31import {TCollectionMode} from '../../../util/playgrounds/types';3233class EthGroupBase {34 helper: EthUniqueHelper;3536 constructor(helper: EthUniqueHelper) {37 this.helper = helper;38 }39}404142class ContractGroup extends EthGroupBase {43 async findImports(imports?: ContractImports[]){44 if(!imports) return function(path: string) {45 return {error: `File not found: ${path}`};46 };4748 const knownImports = {} as {[key: string]: string};49 for(const imp of imports) {50 knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();51 }5253 return function(path: string) {54 if(path in knownImports) return {contents: knownImports[path]};55 return {error: `File not found: ${path}`};56 };57 }5859 async compile(name: string, src: string, imports?: ContractImports[]): Promise<CompiledContract> {60 const out = JSON.parse(solc.compile(JSON.stringify({61 language: 'Solidity',62 sources: {63 [`${name}.sol`]: {64 content: src,65 },66 },67 settings: {68 outputSelection: {69 '*': {70 '*': ['*'],71 },72 },73 },74 }), {import: await this.findImports(imports)})).contracts[`${name}.sol`][name];7576 return {77 abi: out.abi,78 object: '0x' + out.evm.bytecode.object,79 };80 }8182 async deployByCode(signer: string, name: string, src: string, imports?: ContractImports[]): Promise<Contract> {83 const compiledContract = await this.compile(name, src, imports);84 return this.deployByAbi(signer, compiledContract.abi, compiledContract.object);85 }8687 async deployByAbi(signer: string, abi: any, object: string): Promise<Contract> {88 const web3 = this.helper.getWeb3();89 const contract = new web3.eth.Contract(abi, undefined, {90 data: object,91 from: signer,92 gas: this.helper.eth.DEFAULT_GAS,93 });94 return await contract.deploy({data: object}).send({from: signer});95 }9697}9899class NativeContractGroup extends EthGroupBase {100101 contractHelpers(caller: string): Contract {102 const web3 = this.helper.getWeb3();103 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, gas: this.helper.eth.DEFAULT_GAS});104 }105106 collectionHelpers(caller: string) {107 const web3 = this.helper.getWeb3();108 return new web3.eth.Contract(collectionHelpersAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, gas: this.helper.eth.DEFAULT_GAS});109 }110111 collection(address: string, mode: TCollectionMode, caller?: string): Contract {112 const abi = {113 'nft': nonFungibleAbi,114 'rft': refungibleAbi,115 'ft': fungibleAbi,116 }[mode];117 const web3 = this.helper.getWeb3();118 return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});119 }120121 collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {122 return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller);123 }124125 rftToken(address: string, caller?: string): Contract {126 const web3 = this.helper.getWeb3();127 return new web3.eth.Contract(refungibleTokenAbi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});128 }129130 rftTokenById(collectionId: number, tokenId: number, caller?: string): Contract {131 return this.rftToken(this.helper.ethAddress.fromTokenId(collectionId, tokenId), caller);132 }133}134135136class EthGroup extends EthGroupBase {137 DEFAULT_GAS = 2_500_000;138139 createAccount() {140 const web3 = this.helper.getWeb3();141 const account = web3.eth.accounts.create();142 web3.eth.accounts.wallet.add(account.privateKey);143 return account.address;144 }145146 async createAccountWithBalance(donor: IKeyringPair, amount=100n) {147 const account = this.createAccount();148 await this.transferBalanceFromSubstrate(donor, account, amount);149150 return account;151 }152153 async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=100n, inTokens=true) {154 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));155 }156157 async getCollectionCreationFee(signer: string) {158 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);159 return await collectionHelper.methods.collectionCreationFee().call();160 }161162 async sendEVM(signer: IKeyringPair, contractAddress: string, abi: string, value: string, gasLimit?: number) {163 if(!gasLimit) gasLimit = this.DEFAULT_GAS;164 const web3 = this.helper.getWeb3();165 const gasPrice = await web3.eth.getGasPrice();166 // TODO: check execution status167 await this.helper.executeExtrinsic(168 signer,169 'api.tx.evm.call', [this.helper.address.substrateToEth(signer.address), contractAddress, abi, value, gasLimit, gasPrice, null, null, []],170 true,171 );172 }173174 async callEVM(signer: TEthereumAccount, contractAddress: string, abi: string) {175 return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);176 }177 178 async createCollecion(functionName: string, signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {179 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();180 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);181 182 const result = await collectionHelper.methods[functionName](name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});183184 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);185 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);186 const events = this.helper.eth.normalizeEvents(result.events);187 188 return {collectionId, collectionAddress, events};189 }190 191 async createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {192 return this.createCollecion('createNFTCollection', signer, name, description, tokenPrefix);193 }194195 async createERC721MetadataCompatibleNFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {196 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);197198 const {collectionId, collectionAddress, events} = await this.createCollecion('createNFTCollection', signer, name, description, tokenPrefix);199200 await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();201202 return {collectionId, collectionAddress, events};203 }204205 async createRFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {206 return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);207 }208 209 async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {210 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();211 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);212 213 const result = await collectionHelper.methods.createRTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});214215 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);216 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);217 218 const events = this.helper.eth.normalizeEvents(result.events);219 220 return {collectionId, collectionAddress, events};221 }222 223 async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {224 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);225226 const {collectionId, collectionAddress, events} = await this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);227228 await collectionHelper.methods.makeCollectionERC721MetadataCompatible(collectionAddress, baseUri).send();229230 return {collectionId, collectionAddress, events};231 }232233 async deployCollectorContract(signer: string): Promise<Contract> {234 return await this.helper.ethContract.deployByCode(signer, 'Collector', `235 // SPDX-License-Identifier: UNLICENSED236 pragma solidity ^0.8.6;237238 contract Collector {239 uint256 collected;240 fallback() external payable {241 giveMoney();242 }243 function giveMoney() public payable {244 collected += msg.value;245 }246 function getCollected() public view returns (uint256) {247 return collected;248 }249 function getUnaccounted() public view returns (uint256) {250 return address(this).balance - collected;251 }252253 function withdraw(address payable target) public {254 target.transfer(collected);255 collected = 0;256 }257 }258 `);259 }260261 async deployFlipper(signer: string): Promise<Contract> {262 return await this.helper.ethContract.deployByCode(signer, 'Flipper', `263 // SPDX-License-Identifier: UNLICENSED264 pragma solidity ^0.8.6;265266 contract Flipper {267 bool value = false;268 function flip() public {269 value = !value;270 }271 function getValue() public view returns (bool) {272 return value;273 }274 }275 `);276 }277278 async recordCallFee(user: string, call: () => Promise<any>): Promise<bigint> {279 const before = await this.helper.balance.getEthereum(user);280 await call();281 // In dev mode, the transaction might not finish processing in time282 await this.helper.wait.newBlocks(1);283 const after = await this.helper.balance.getEthereum(user);284285 return before - after;286 }287288 normalizeEvents(events: any): NormalizedEvent[] {289 const output = [];290 for (const key of Object.keys(events)) {291 if (key.match(/^[0-9]+$/)) {292 output.push(events[key]);293 } else if (Array.isArray(events[key])) {294 output.push(...events[key]);295 } else {296 output.push(events[key]);297 }298 }299 output.sort((a, b) => a.logIndex - b.logIndex);300 return output.map(({address, event, returnValues}) => {301 const args: { [key: string]: string } = {};302 for (const key of Object.keys(returnValues)) {303 if (!key.match(/^[0-9]+$/)) {304 args[key] = returnValues[key];305 }306 }307 return {308 address,309 event,310 args,311 };312 });313 }314315 async calculateFee(address: ICrossAccountId, code: () => Promise<any>): Promise<bigint> {316 const wrappedCode = async () => {317 await code();318 // In dev mode, the transaction might not finish processing in time319 await this.helper.wait.newBlocks(1);320 };321 return await this.helper.arrange.calculcateFee(address, wrappedCode);322 }323}324325class EthAddressGroup extends EthGroupBase {326 extractCollectionId(address: string): number {327 if (!(address.length === 42 || address.length === 40)) throw new Error('address wrong format');328 return parseInt(address.substr(address.length - 8), 16);329 }330331 fromCollectionId(collectionId: number): string {332 if (collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');333 return Web3.utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8,'0')}`);334 }335336 extractTokenId(address: string): {collectionId: number, tokenId: number} {337 if (!address.startsWith('0x'))338 throw 'address not starts with "0x"';339 if (address.length > 42)340 throw 'address length is more than 20 bytes';341 return {342 collectionId: Number('0x' + address.substring(address.length - 16, address.length - 8)),343 tokenId: Number('0x' + address.substring(address.length - 8)),344 };345 }346347 fromTokenId(collectionId: number, tokenId: number): string {348 return this.helper.util.getTokenAddress({collectionId, tokenId});349 }350351 normalizeAddress(address: string): string {352 return '0x' + address.substring(address.length - 40);353 }354} 355356export class EthPropertyGroup extends EthGroupBase {357 property(key: string, value: string): EthProperty {358 return [359 key, 360 '0x'+Buffer.from(value).toString('hex'),361 ];362 }363}364export type EthUniqueHelperConstructor = new (...args: any[]) => EthUniqueHelper;365366export class EthCrossAccountGroup extends EthGroupBase {367 fromAddress(address: TEthereumAccount): TEthCrossAccount {368 return {369 0: address,370 1: '0',371 field_0: address,372 field_1: '0',373 };374 }375376 fromKeyringPair(keyring: IKeyringPair): TEthCrossAccount {377 return {378 0: '0x0000000000000000000000000000000000000000',379 1: keyring.addressRaw,380 field_0: '0x0000000000000000000000000000000000000000',381 field_1: keyring.addressRaw,382 };383 }384}385386export class EthUniqueHelper extends DevUniqueHelper {387 web3: Web3 | null = null;388 web3Provider: WebsocketProvider | null = null;389390 eth: EthGroup;391 ethAddress: EthAddressGroup;392 ethNativeContract: NativeContractGroup;393 ethContract: ContractGroup;394 ethCrossAccount: EthCrossAccountGroup;395 ethProperty: EthPropertyGroup;396397 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {398 options.helperBase = options.helperBase ?? EthUniqueHelper;399400 super(logger, options);401 this.eth = new EthGroup(this);402 this.ethAddress = new EthAddressGroup(this);403 this.ethCrossAccount = new EthCrossAccountGroup(this);404 this.ethNativeContract = new NativeContractGroup(this);405 this.ethContract = new ContractGroup(this);406 this.ethProperty = new EthPropertyGroup(this);407 }408409 getWeb3(): Web3 {410 if(this.web3 === null) throw Error('Web3 not connected');411 return this.web3;412 }413414 async connectWeb3(wsEndpoint: string) {415 if(this.web3 !== null) return;416 this.web3Provider = new Web3.providers.WebsocketProvider(wsEndpoint);417 this.web3 = new Web3(this.web3Provider);418 }419420 async disconnect() {421 if(this.web3 === null) return;422 this.web3Provider?.connection.close();423424 await super.disconnect();425 }426427 clearApi() {428 super.clearApi();429 this.web3 = null;430 }431432 clone(helperCls: EthUniqueHelperConstructor, options?: { [key: string]: any; }): EthUniqueHelper {433 const newHelper = super.clone(helperCls, options) as EthUniqueHelper;434 newHelper.web3 = this.web3;435 newHelper.web3Provider = this.web3Provider;436437 return newHelper;438 }439}