Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try fixing test against fork CI job #1388

Closed
wants to merge 8 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/runtime-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ jobs:
--bootnodes "${{ needs.setup.outputs.boot_node }}" \
--prometheus-external \
--telemetry-url "wss://telemetry.creditcoin.network/submit/ 0" \
--base-path /mnt \
--public-addr "/dns4/$IP_ADDRESS/tcp/50555" \
--port 50555 >creditcoin-node-used-for-fork.log 2>&1 &

Expand All @@ -214,7 +215,7 @@ jobs:

./creditcoin-fork --bin ./creditcoin-node --orig ${{ needs.setup.outputs.target_chain }} \
--base dev --name Development \
-o creditcoin-fork.json --rpc ws://127.0.0.1:9944
-o creditcoin-fork.json --rpc ws://127.0.0.1:9944 --exclude-pallets PosSwitch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why exclude the PosSwitch pallet ? What's the reasoning here?


- name: TERM creditcoin-node
continue-on-error: true
Expand Down
11 changes: 8 additions & 3 deletions creditcoin-js/src/ctc-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ const deployCtcToken = async (deployer: Signer, existingAddress: string | undefi
return ctcToken;
};

const burnCtc = async (ctcToken: GluwaCreditVestingToken, howMuch: string) => {
export const burnCtc = async (ctcToken: GluwaCreditVestingToken, howMuch: string, writeToEnv = false) => {
const tx = await ctcToken.burn(howMuch);
const txHash = tx.hash;

// wait for tx to be mined and get receipt
await tx.wait();

console.log('Burn Tx hash', txHash);
process.env.CREDITCOIN_CTC_BURN_TX_HASH = txHash;
if (writeToEnv) {
process.env.CREDITCOIN_CTC_BURN_TX_HASH = txHash;
}
return txHash;
};

export const deployCtcContract = async (
Expand All @@ -45,7 +48,9 @@ export const deployCtcContract = async (
const deployer = new Wallet(deployerPrivateKey, provider);
const ctcToken = await deployCtcToken(deployer, existingAddress);

await burnCtc(ctcToken, howMuchToBurn);
await burnCtc(ctcToken, howMuchToBurn, true);

return ctcToken;
};

export const deployGATEToken = async (deployer: Signer, existingAddress: string | undefined): Promise<any> => {
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/src/creditcoinForkSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const setup = async () => {

(global as any).CREDITCOIN_SWITCH_TO_POS_ALREADY_CALLED = process.env.SWITCH_TO_POS_ALREADY_CALLED === '1';

(global as any).CREDITCOIN_USES_FAST_RUNTIME = false;

await globalSetup();
};

Expand Down
9 changes: 8 additions & 1 deletion integration-tests/src/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ApiPromise, WsProvider, Keyring, KeyringPair, Wallet, POINT_01_CTC } from 'creditcoin-js';
import { setupAuthority } from 'creditcoin-js/lib/examples/setup-authority';
import { deployCtcContract } from 'creditcoin-js/lib/ctc-deploy';
import { GluwaCreditVestingToken } from 'creditcoin-js/lib/examples/ctc/typechain';

const createSigner = (keyring: Keyring, who: 'lender' | 'borrower' | 'sudo'): KeyringPair => {
switch (who) {
Expand All @@ -15,6 +16,11 @@ const createSigner = (keyring: Keyring, who: 'lender' | 'borrower' | 'sudo'): Ke
}
};

declare global {
// eslint-disable-next-line no-var
var CREDITCOIN_CTC_CONTRACT: GluwaCreditVestingToken;
}

const setup = async () => {
process.env.NODE_ENV = 'test';

Expand Down Expand Up @@ -87,11 +93,12 @@ const setup = async () => {
}

// Note: in case address is defined will attach to already deployed contract
await deployCtcContract(
const contract = await deployCtcContract(
(global as any).CREDITCOIN_CTC_CONTRACT_ADDRESS,
(global as any).CREDITCOIN_ETHEREUM_NODE_URL,
(global as any).CREDITCOIN_CTC_DEPLOYER_PRIVATE_KEY,
);
global.CREDITCOIN_CTC_CONTRACT = contract;
(global as any).CREDITCOIN_CTC_CONTRACT_ADDRESS = process.env.CREDITCOIN_CTC_CONTRACT_ADDRESS;

if ((global as any).CREDITCOIN_CTC_BURN_TX_HASH === undefined) {
Expand Down
18 changes: 10 additions & 8 deletions integration-tests/src/test/collect-coins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Blockchain } from 'creditcoin-js/lib/model';
import { CreditcoinApi } from 'creditcoin-js/lib/types';
import { testData, tryRegisterAddress } from 'creditcoin-js/lib/testUtils';
import { testIf } from '../utils';
import { CREDO_PER_CTC, burnCtc } from 'creditcoin-js/lib/ctc-deploy';

describe('CollectCoins', (): void => {
let ccApi: CreditcoinApi;
Expand Down Expand Up @@ -35,6 +36,8 @@ describe('CollectCoins', (): void => {
let collector: KeyringPair;
let deployerWallet: Wallet;
let deployerRegAddr: AddressRegistered;
let failBurnTxHash: string;
let persistBurnTxHash: string;

beforeAll(async () => {
const {
Expand Down Expand Up @@ -64,6 +67,9 @@ describe('CollectCoins', (): void => {
collector,
(global as any).CREDITCOIN_REUSE_EXISTING_ADDRESSES,
);
const oneCtc = (1 * CREDO_PER_CTC).toString();
failBurnTxHash = await burnCtc(global.CREDITCOIN_CTC_CONTRACT, oneCtc);
persistBurnTxHash = await burnCtc(global.CREDITCOIN_CTC_CONTRACT, oneCtc);
}, 300_000);

testIf((global as any).CREDITCOIN_EXECUTE_SETUP_AUTHORITY, 'fee is min 0.01 CTC', async (): Promise<void> => {
Expand Down Expand Up @@ -100,7 +106,7 @@ describe('CollectCoins', (): void => {
const collectCoinsEvent = await requestCollectCoins(
secondRegAddr.item.externalAddress,
collector,
(global as any).CREDITCOIN_CTC_BURN_TX_HASH,
failBurnTxHash,
);

// eventhough collector (a Creditcoin account) has control over both Ethereum wallets
Expand All @@ -119,19 +125,15 @@ describe('CollectCoins', (): void => {
const collectCoinsEvent = await requestCollectCoins(
deployerRegAddr.item.externalAddress,
collector,
(global as any).CREDITCOIN_CTC_BURN_TX_HASH,
persistBurnTxHash,
);

const collectCoinsVerified = await collectCoinsEvent.waitForVerification(800_000).catch();
const collectCoinsVerified = await collectCoinsEvent.waitForVerification(800_000);
expect(collectCoinsVerified).toBeTruthy();

// try again - should fail
await expect(
requestCollectCoins(
deployerRegAddr.item.externalAddress,
collector,
(global as any).CREDITCOIN_CTC_BURN_TX_HASH,
),
requestCollectCoins(deployerRegAddr.item.externalAddress, collector, persistBurnTxHash),
).rejects.toThrow(
'creditcoin.CollectCoinsAlreadyRegistered: The coin collection has already been registered',
);
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/src/test/gate-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ describe('Test GATE Token', (): void => {
);
const gateContract = GATEContract(deployer.address, burnTx.hash);

// Make sure gate contract is unset
await api.tx.sudo
.sudo(api.tx.system.killStorage(['0xd766358cca00233e6155d7c14e2c085f09d6ade1839fafee2303010e35dfd1a5']))
.signAndSend(sudoSigner, { nonce: -1 });

// Test #1: The extrinsic should erorr when the faucet address has not been set
await expect(requestCollectCoinsV2(gateContract, sudoSigner)).rejects.toThrow(
'creditcoin.BurnGATEFaucetNotSet',
Expand Down
Loading