diff --git a/integration-tests/src/test/gate-token.test.ts b/integration-tests/src/test/gate-token.test.ts deleted file mode 100644 index a5cbc3b24..000000000 --- a/integration-tests/src/test/gate-token.test.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { KeyringPair, creditcoinApi, Keyring } from 'creditcoin-js'; -import { Blockchain } from 'creditcoin-js/lib/model'; -import { CreditcoinApi } from 'creditcoin-js/lib/types'; -import { testData, tryRegisterAddress } from 'creditcoin-js/lib/testUtils'; - -import { deployGATEToken } from 'creditcoin-js/lib/ctc-deploy'; -import { JsonRpcProvider } from '@ethersproject/providers'; -import { Wallet } from 'ethers'; -import { mnemonicGenerate } from '@polkadot/util-crypto'; -import { signAccountId } from 'creditcoin-js/lib/utils'; -import { testIf } from '../utils'; - -describe('Test GATE Token', (): void => { - let ccApi: CreditcoinApi; - let sudoSigner: KeyringPair; - - // Needed to interact with the ethererum private node - const testingData = testData( - (global as any).CREDITCOIN_ETHEREUM_CHAIN as Blockchain, - (global as any).CREDITCOIN_CREATE_WALLET, - ); - const { keyring } = testingData; - const provider = new JsonRpcProvider((global as any).CREDITCOIN_ETHEREUM_NODE_URL); - const deployer = new Wallet((global as any).CREDITCOIN_CTC_DEPLOYER_PRIVATE_KEY, provider); - const burnAmount = 200; - - // Holds the reference to the deployed GATE contract - let gateToken: any; - const gateKeyring = new Keyring({ type: 'ed25519', ss58Format: 3 }); - const gateFaucet = gateKeyring.addFromUri(mnemonicGenerate(12)); - - beforeAll(async () => { - gateToken = await deployGATEToken(deployer, undefined); - - ccApi = await creditcoinApi((global as any).CREDITCOIN_API_URL); - if ((global as any).CREDITCOIN_EXECUTE_SETUP_AUTHORITY) { - sudoSigner = (global as any).CREDITCOIN_CREATE_SIGNER(keyring, 'sudo'); - } - }); - - afterAll(async () => { - await ccApi.api.disconnect(); - }); - - testIf( - (global as any).CREDITCOIN_EXECUTE_SETUP_AUTHORITY, - 'End to end', - async () => { - const { api } = ccApi; - - await api.tx.sudo - .sudo(api.tx.balances.setBalance(gateFaucet.address, 1000, 0)) - .signAndSend(sudoSigner, { nonce: -1 }); - - // Set the on chain location for the burn contract to be the address of the deployer wallet - const contract = api.createType('PalletCreditcoinOcwTasksCollectCoinsDeployedContract', { - address: gateToken.address, - chain: testingData.blockchain, - }); - await api.tx.sudo.sudo(api.tx.creditcoin.setGateContract(contract)).signAndSend(sudoSigner, { nonce: -1 }); - - const mintTx = await gateToken.mint(deployer.address, 2500); - await mintTx.wait(3); - const balance = await gateToken.balanceOf(deployer.address); - expect(balance.eq(2500)).toBe(true); - - const burnTx = await gateToken.burn(burnAmount); - await burnTx.wait(3); - - // We are using the same deployer address as GCRE so the address may already be registered - await tryRegisterAddress( - ccApi, - deployer.address, - testingData.blockchain, - signAccountId(api, deployer, sudoSigner.address), - sudoSigner, - (global as any).CREDITCOIN_REUSE_EXISTING_ADDRESSES, - ); - - // Make sure gate contract is unset - await api.tx.sudo - .sudo(api.tx.system.killStorage(['0xd766358cca00233e6155d7c14e2c085f09d6ade1839fafee2303010e35dfd1a5'])) - .signAndSend(sudoSigner, { nonce: -1 }); - - await api.tx.sudo - .sudo(api.tx.creditcoin.setGateFaucet(gateFaucet.address)) - .signAndSend(sudoSigner, { nonce: -1 }); - }, - 900_000, - ); -}); diff --git a/integration-tests/src/test/set-gate-contract.test.ts b/integration-tests/src/test/set-gate-contract.test.ts deleted file mode 100644 index 96c677d4e..000000000 --- a/integration-tests/src/test/set-gate-contract.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { KeyringPair, creditcoinApi } from 'creditcoin-js'; -import { Blockchain } from 'creditcoin-js/lib/model'; -import { CreditcoinApi } from 'creditcoin-js/lib/types'; -import { testData } from 'creditcoin-js/lib/testUtils'; - -import { extractFee, describeIf } from '../utils'; - -describeIf((global as any).CREDITCOIN_EXECUTE_SETUP_AUTHORITY, 'SetGateContract', (): void => { - let ccApi: CreditcoinApi; - let sudoSigner: KeyringPair; - const testingData = testData( - (global as any).CREDITCOIN_ETHEREUM_CHAIN as Blockchain, - (global as any).CREDITCOIN_CREATE_WALLET, - ); - const { keyring } = testingData; - - beforeAll(async () => { - ccApi = await creditcoinApi((global as any).CREDITCOIN_API_URL); - sudoSigner = (global as any).CREDITCOIN_CREATE_SIGNER(keyring, 'sudo'); - }); - - afterAll(async () => { - await ccApi.api.disconnect(); - }); - - it('fee is min 0.01 CTC', async (): Promise => { - const { api } = ccApi; - - /* eslint-disable @typescript-eslint/naming-convention */ - const contract = api.createType('PalletCreditcoinOcwTasksCollectCoinsDeployedContract', { - // for testing purposes I can use any address b/c I'm only interested in the transaction fee - address: '0xa3EE21C306A700E682AbCdfe9BaA6A08F3820419', - chain: testingData.blockchain, - }); - - return new Promise((resolve, reject): void => { - const unsubscribe = api.tx.sudo - .sudo(api.tx.creditcoin.setGateContract(contract)) - .signAndSend(sudoSigner, { nonce: -1 }, async ({ dispatchError, events, status }) => { - await extractFee(resolve, reject, unsubscribe, api, dispatchError, events, status); - }) - .catch((error) => reject(error)); - }).then((fee) => { - expect(fee).toBeGreaterThanOrEqual((global as any).CREDITCOIN_MINIMUM_TXN_FEE); - }); - }); -}); diff --git a/integration-tests/src/test/set-gate-faucet.test.ts b/integration-tests/src/test/set-gate-faucet.test.ts deleted file mode 100644 index fc98b3be7..000000000 --- a/integration-tests/src/test/set-gate-faucet.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { KeyringPair, creditcoinApi } from 'creditcoin-js'; -import { Blockchain } from 'creditcoin-js/lib/model'; -import { CreditcoinApi } from 'creditcoin-js/lib/types'; -import { testData } from 'creditcoin-js/lib/testUtils'; - -import { extractFee, describeIf } from '../utils'; - -describeIf((global as any).CREDITCOIN_EXECUTE_SETUP_AUTHORITY, 'SetGateFaucet', (): void => { - let ccApi: CreditcoinApi; - let sudoSigner: KeyringPair; - const testingData = testData( - (global as any).CREDITCOIN_ETHEREUM_CHAIN as Blockchain, - (global as any).CREDITCOIN_CREATE_WALLET, - ); - const { keyring } = testingData; - - beforeAll(async () => { - ccApi = await creditcoinApi((global as any).CREDITCOIN_API_URL); - sudoSigner = (global as any).CREDITCOIN_CREATE_SIGNER(keyring, 'sudo'); - }); - - afterAll(async () => { - await ccApi.api.disconnect(); - }); - - it('fee is min 0.01 CTC', async (): Promise => { - const { api } = ccApi; - - return new Promise((resolve, reject): void => { - const unsubscribe = api.tx.sudo - // for testing purposes I can use any address b/c I'm only interested in the transaction fee - .sudo(api.tx.creditcoin.setGateFaucet(sudoSigner.address)) - .signAndSend(sudoSigner, { nonce: -1 }, async ({ dispatchError, events, status }) => { - await extractFee(resolve, reject, unsubscribe, api, dispatchError, events, status); - }) - .catch((error) => reject(error)); - }).then((fee) => { - expect(fee).toBeGreaterThanOrEqual((global as any).CREDITCOIN_MINIMUM_TXN_FEE); - }); - }); -}); diff --git a/pallets/creditcoin/src/benchmarking.rs b/pallets/creditcoin/src/benchmarking.rs index 8adbab3dc..7e9a10075 100644 --- a/pallets/creditcoin/src/benchmarking.rs +++ b/pallets/creditcoin/src/benchmarking.rs @@ -285,16 +285,6 @@ benchmarks! { let signature = ecdsa_sign(ktypeid, &pkey, &message).expect("ecdsa signature"); let proof = OwnershipProof::EthSign(signature); }: _(RawOrigin::Signed(who), Blockchain::Ethereum, address, proof) - - set_gate_contract { - let root = RawOrigin::Root; - let contract = DeployedContract::default(); - }: _(root, contract) - - set_gate_faucet { - let root = RawOrigin::Root; - let addr: T::AccountId = lender_account::(false); - }: _(root, addr) } fn generate_funded_deal( diff --git a/pallets/creditcoin/src/lib.rs b/pallets/creditcoin/src/lib.rs index b8c1c237a..2fa1ff00e 100644 --- a/pallets/creditcoin/src/lib.rs +++ b/pallets/creditcoin/src/lib.rs @@ -148,8 +148,6 @@ pub mod pallet { fn register_deal_order() -> Weight; fn remove_authority() -> Weight; fn register_address_v2() -> Weight; - fn set_gate_contract() -> Weight; - fn set_gate_faucet() -> Weight; } #[pallet::pallet] @@ -1399,26 +1397,5 @@ pub mod pallet { }, } } - - /// Set the onchain details for the Gluwa GATE Contract, including its address and the blockchain where it is deployed. - /// This extrinsic expects the caller to have root permissions. - #[pallet::call_index(23)] - #[pallet::weight(::WeightInfo::set_gate_contract())] - pub fn set_gate_contract( - origin: OriginFor, - contract: DeployedContract, - ) -> DispatchResult { - ensure_root(origin)?; - GATEContract::::put(contract); - Ok(()) - } - - #[pallet::call_index(24)] - #[pallet::weight(::WeightInfo::set_gate_faucet())] - pub fn set_gate_faucet(origin: OriginFor, address: T::AccountId) -> DispatchResult { - ensure_root(origin)?; - GATEFaucetAccount::::put(address); - Ok(()) - } } } diff --git a/pallets/creditcoin/src/tests.rs b/pallets/creditcoin/src/tests.rs index 75f6194df..719fe56b9 100644 --- a/pallets/creditcoin/src/tests.rs +++ b/pallets/creditcoin/src/tests.rs @@ -2928,12 +2928,6 @@ fn exercise_weightinfo_functions() { let result = super::weights::WeightInfo::::register_address_v2(); assert!(result.ref_time() > 0); - - let result = super::weights::WeightInfo::::set_gate_contract(); - assert!(result.ref_time() > 0); - - let result = super::weights::WeightInfo::::set_gate_faucet(); - assert!(result.ref_time() > 0); } #[test] @@ -3246,60 +3240,6 @@ fn gate_contract_storage_should_return_default_goerli_contract_when_not_set() { }); } -#[test] -fn set_gate_contract_should_fail_when_not_signed_by_root() { - ExtBuilder::default().build_and_execute(|| { - let acct: AccountId = AccountId::new([0; 32]); - let gate_contract = DeployedContract::default(); - - assert_noop!(Creditcoin::set_gate_contract(Origin::signed(acct), gate_contract), BadOrigin); - }); -} - -#[test] -fn set_gate_contract_passes_and_storage_is_updated() { - ExtBuilder::default().build_and_execute(|| { - let fake_address = - sp_core::H160([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]); - - let gate_contract = - DeployedContract { address: fake_address, chain: Blockchain::Luniverse }; - - assert_ne!(gate_contract, DeployedContract::default()); - assert_eq!(Creditcoin::gate_contract(), DeployedContract::default()); - assert_ok!(Creditcoin::set_gate_contract(RawOrigin::Root.into(), gate_contract)); - - let stored_contract = Creditcoin::gate_contract(); - - assert_eq!(stored_contract.address, fake_address); - assert_eq!(stored_contract.chain, Blockchain::Luniverse); - }); -} - -#[test] -fn set_gate_faucet_should_fail_when_not_signed_by_root() { - ExtBuilder::default().build_and_execute(|| { - let acct: AccountId = AccountId::new([0; 32]); - - assert_noop!(Creditcoin::set_gate_faucet(Origin::signed(acct.clone()), acct), BadOrigin); - }); -} - -#[test] -fn set_gate_faucet_passes_and_storage_is_updated() { - ExtBuilder::default().build_and_execute(|| { - let addr: AccountId = AccountId::new([0; 32]); - - assert!(Creditcoin::gate_faucet_account().is_none()); - assert_ok!(Creditcoin::set_gate_faucet(RawOrigin::Root.into(), addr.clone())); - - let faucet_addr: Option = Creditcoin::gate_faucet_account(); - - assert!(faucet_addr.is_some()); - assert_eq!(faucet_addr.unwrap(), addr) - }); -} - #[test] fn gate_faucet_account_storage_should_return_none_when_not_set() { ExtBuilder::default().build_and_execute(|| { diff --git a/pallets/creditcoin/src/types/collect_coins.rs b/pallets/creditcoin/src/types/collect_coins.rs index 76a9db4ae..2ab176ed2 100644 --- a/pallets/creditcoin/src/types/collect_coins.rs +++ b/pallets/creditcoin/src/types/collect_coins.rs @@ -1,6 +1,5 @@ -use crate::types::{AddressId, Blockchain, ExternalAddress, ExternalTxId, SystemConfig}; +use crate::types::{AddressId, Blockchain, ExternalTxId, SystemConfig}; use frame_support::RuntimeDebug; -use ocw::tasks::collect_coins::DeployedContract; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; @@ -12,14 +11,6 @@ pub struct CollectedCoins { pub contract_type: ContractType, } -#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct UnverifiedCollectedCoins { - pub to: ExternalAddress, - pub tx_id: ExternalTxId, - pub contract: DeployedContract, - pub contract_type: ContractType, -} - #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct CollectedCoinsId(Hash); @@ -53,7 +44,6 @@ impl From for CollectedCoinsId { Self(hash) } } -use crate::ocw; use crate::types::concatenate; use sp_runtime::traits::Hash; diff --git a/pallets/creditcoin/src/weights.rs b/pallets/creditcoin/src/weights.rs index 0d16cd4cb..eb9c236dc 100644 --- a/pallets/creditcoin/src/weights.rs +++ b/pallets/creditcoin/src/weights.rs @@ -377,26 +377,4 @@ impl crate::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: Creditcoin GATEContract (r:0 w:1) - /// Proof: Creditcoin GATEContract (max_values: Some(1), max_size: Some(279), added: 774, mode: MaxEncodedLen) - fn set_gate_contract() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 6_100_000 picoseconds. - Weight::from_parts(6_600_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: Creditcoin GATEFaucetAccount (r:0 w:1) - /// Proof: Creditcoin GATEFaucetAccount (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) - fn set_gate_faucet() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 6_000_000 picoseconds. - Weight::from_parts(6_700_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - .saturating_add(T::DbWeight::get().writes(1)) - } }