Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion creditcoin-js/creditcoin.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions creditcoin-js/src/interfaces/augment-api-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ declare module '@polkadot/api-base/types/storage' {
[]
> &
QueryableStorageEntry<ApiType, []>;
gateFaucetAddress: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> &
QueryableStorageEntry<ApiType, []>;
legacyBalanceKeeper: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> &
QueryableStorageEntry<ApiType, []>;
legacyWallets: AugmentedQuery<
Expand Down
4 changes: 4 additions & 0 deletions creditcoin-js/src/interfaces/augment-api-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ declare module '@polkadot/api-base/types/submittable' {
) => SubmittableExtrinsic<ApiType>,
[PalletCreditcoinOcwTasksCollectCoinsDeployedContract]
>;
setGateFaucet: AugmentedSubmittable<
(address: AccountId32 | string | Uint8Array) => SubmittableExtrinsic<ApiType>,
[AccountId32]
>;
/**
* Generic tx
**/
Expand Down
3 changes: 3 additions & 0 deletions creditcoin-js/src/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,9 @@ export default {
set_gate_contract: {
contract: 'PalletCreditcoinOcwTasksCollectCoinsDeployedContract',
},
set_gate_faucet: {
address: 'AccountId32',
},
},
},
/**
Expand Down
7 changes: 6 additions & 1 deletion creditcoin-js/src/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,10 @@ declare module '@polkadot/types/lookup' {
readonly asSetGateContract: {
readonly contract: PalletCreditcoinOcwTasksCollectCoinsDeployedContract;
} & Struct;
readonly isSetGateFaucet: boolean;
readonly asSetGateFaucet: {
readonly address: AccountId32;
} & Struct;
readonly type:
| 'ClaimLegacyWallet'
| 'RegisterAddress'
Expand All @@ -2179,7 +2183,8 @@ declare module '@polkadot/types/lookup' {
| 'SetCollectCoinsContract'
| 'RemoveAuthority'
| 'RegisterAddressV2'
| 'SetGateContract';
| 'SetGateContract'
| 'SetGateFaucet';
}

/** @name SpCoreEcdsaPublic (264) */
Expand Down
4 changes: 1 addition & 3 deletions integration-tests/src/test/set-gate-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ describeIf((global as any).CREDITCOIN_EXECUTE_SETUP_AUTHORITY, 'SetGateContract'

beforeAll(async () => {
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, 'lender');
}
sudoSigner = (global as any).CREDITCOIN_CREATE_SIGNER(keyring, 'lender');
});

afterAll(async () => {
Expand Down
41 changes: 41 additions & 0 deletions integration-tests/src/test/set-gate-faucet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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, 'lender');
});

afterAll(async () => {
await ccApi.api.disconnect();
});

it('fee is min 0.01 CTC', async (): Promise<void> => {
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);
});
});
});
6 changes: 6 additions & 0 deletions pallets/creditcoin/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ benchmarks! {
let root = RawOrigin::Root;
let contract = DeployedContract::default();
}: _(root, contract)


set_gate_faucet {
let root = RawOrigin::Root;
let addr: T::AccountId = lender_account::<T>(false);
}: _(root, addr)
}

//impl_benchmark_test_suite!(Creditcoin, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
14 changes: 14 additions & 0 deletions pallets/creditcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub mod pallet {
fn set_collect_coins_contract() -> Weight;
fn register_address_v2() -> Weight;
fn set_gate_contract() -> Weight;
fn set_gate_faucet() -> Weight;
}

#[pallet::pallet]
Expand Down Expand Up @@ -236,6 +237,10 @@ pub mod pallet {
#[pallet::getter(fn gate_contract)]
pub type GATEContract<T: Config> = StorageValue<_, DeployedContract, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn gate_faucet_address)]
pub type GATEFaucetAddress<T: Config> = StorageValue<_, T::AccountId, OptionQuery>;
Comment thread
nathanwhit marked this conversation as resolved.

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down Expand Up @@ -1420,5 +1425,14 @@ pub mod pallet {
GATEContract::<T>::put(contract);
Ok(())
}

#[transactional]
Comment thread
nathanwhit marked this conversation as resolved.
#[pallet::call_index(24)]
#[pallet::weight(<T as Config>::WeightInfo::set_gate_faucet())]
pub fn set_gate_faucet(origin: OriginFor<T>, address: T::AccountId) -> DispatchResult {
ensure_root(origin)?;
GATEFaucetAddress::<T>::put(address);
Ok(())
}
}
}
36 changes: 36 additions & 0 deletions pallets/creditcoin/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2938,6 +2938,9 @@ fn exercise_weightinfo_functions() {

let result = super::weights::WeightInfo::<Test>::set_gate_contract();
assert!(result.ref_time() > 0);

let result = super::weights::WeightInfo::<Test>::set_gate_faucet();
assert!(result.ref_time() > 0);
}

#[test]
Expand Down Expand Up @@ -3279,3 +3282,36 @@ fn set_gate_contract_passes_and_storage_is_updated() {
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_address().is_none());
assert_ok!(Creditcoin::set_gate_faucet(RawOrigin::Root.into(), addr.clone()));

let faucet_addr: Option<AccountId32> = Creditcoin::gate_faucet_address();

assert!(faucet_addr.is_some());
assert_eq!(faucet_addr.unwrap(), addr)
});
}

#[test]
fn gate_faucet_address_storage_should_return_none_when_not_set() {
ExtBuilder::default().build_and_execute(|| {
let gate_faucet = Creditcoin::gate_faucet_address();

assert!(gate_faucet.is_none());
});
}
4 changes: 4 additions & 0 deletions pallets/creditcoin/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,8 @@ impl<T: frame_system::Config> crate::WeightInfo for WeightInfo<T> {
fn set_gate_contract() -> Weight {
Weight::from_parts(1,1)
}

fn set_gate_faucet() -> Weight {
Weight::from_parts(1,1)
}
}