forked from cerc-io/registry-sdk
Prathamesh Musale
6a17b1b175
Part of [Create a public laconicd testnet](https://www.notion.so/Create-a-public-laconicd-testnet-896a11bdd8094eff8f1b49c0be0ca3b8) - Add an option for setting gas price - Use fees as gas estimation multiplier when `gasPrice` is provided (following `cosmjs` pattern) - Default gas estimation multiplier: `2` - Add a method to query bonds by owners and fix tests - Add a test for inclusion of batch of txs sent at once in the same block Co-authored-by: IshaVenikar <ishavenikar7@gmail.com> Co-authored-by: Nabarun <nabarun@deepstacksoft.com> Reviewed-on: cerc-io/registry-sdk#22 Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com> Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
127 lines
3.6 KiB
TypeScript
127 lines
3.6 KiB
TypeScript
import { Wallet } from 'ethers';
|
|
|
|
import { DirectSecp256k1Wallet, AccountData as CosmosAccount } from '@cosmjs/proto-signing';
|
|
|
|
import { Registry, Account, ONBOARDING_DISABLED_ERROR } from './index';
|
|
import { getConfig } from './testing/helper';
|
|
import { Participant } from './proto/cerc/onboarding/v1/onboarding';
|
|
|
|
const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig();
|
|
|
|
jest.setTimeout(90 * 1000);
|
|
|
|
const DUMMY_ROLE = 'validator';
|
|
const DUMMY_KYC_ID = 'dummyKycId';
|
|
|
|
const onboardingEnabledTests = () => {
|
|
let registry: Registry;
|
|
let ethWallet: Wallet;
|
|
let cosmosWallet: CosmosAccount;
|
|
let expectedParticipants: Participant[] = [];
|
|
|
|
beforeAll(async () => {
|
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
|
|
|
const mnemonic = Account.generateMnemonic();
|
|
ethWallet = Wallet.fromMnemonic(mnemonic);
|
|
|
|
const accountWallet = await DirectSecp256k1Wallet.fromKey(Buffer.from(privateKey, 'hex'), 'laconic');
|
|
[cosmosWallet] = await accountWallet.getAccounts();
|
|
|
|
expectedParticipants = [
|
|
{
|
|
cosmosAddress: cosmosWallet.address,
|
|
nitroAddress: ethWallet.address,
|
|
role: DUMMY_ROLE,
|
|
kycId: DUMMY_KYC_ID
|
|
}
|
|
];
|
|
});
|
|
|
|
test('Onboard participant.', async () => {
|
|
const ethPayload = {
|
|
address: ethWallet.address,
|
|
msg: 'Message signed by ethereum private key'
|
|
};
|
|
|
|
const message = JSON.stringify(ethPayload);
|
|
const ethSignature = await ethWallet.signMessage(message);
|
|
|
|
await registry.onboardParticipant({
|
|
ethPayload,
|
|
ethSignature,
|
|
role: DUMMY_ROLE,
|
|
kycId: DUMMY_KYC_ID
|
|
}, privateKey, fee);
|
|
});
|
|
|
|
test('Query participants.', async () => {
|
|
const participants = await registry.getParticipants();
|
|
expect(participants).toEqual(expectedParticipants);
|
|
});
|
|
|
|
test('Query participant by address.', async () => {
|
|
const participant = await registry.getParticipantByAddress(cosmosWallet.address);
|
|
expect(participant).toEqual(expectedParticipants[0]);
|
|
});
|
|
|
|
test('Query participant by Nitro address.', async () => {
|
|
const participant = await registry.getParticipantByNitroAddress(ethWallet.address);
|
|
expect(participant).toEqual(expectedParticipants[0]);
|
|
});
|
|
};
|
|
|
|
const onboardingDisabledTests = () => {
|
|
let registry: Registry;
|
|
let ethWallet: Wallet;
|
|
|
|
beforeAll(async () => {
|
|
registry = new Registry(gqlEndpoint, rpcEndpoint, { chainId });
|
|
});
|
|
|
|
test('Error on onboarding attempt.', async () => {
|
|
const mnemonic = Account.generateMnemonic();
|
|
ethWallet = Wallet.fromMnemonic(mnemonic);
|
|
|
|
const ethPayload = {
|
|
address: ethWallet.address,
|
|
msg: 'Message signed by ethereum private key'
|
|
};
|
|
|
|
const message = JSON.stringify(ethPayload);
|
|
const ethSignature = await ethWallet.signMessage(message);
|
|
|
|
try {
|
|
await registry.onboardParticipant({
|
|
ethPayload,
|
|
ethSignature,
|
|
role: DUMMY_ROLE,
|
|
kycId: DUMMY_KYC_ID
|
|
}, privateKey, fee);
|
|
} catch (error: any) {
|
|
expect(error.toString()).toContain(ONBOARDING_DISABLED_ERROR);
|
|
}
|
|
});
|
|
|
|
test('No participants onboarded.', async () => {
|
|
const expectedParticipants: Participant[] = [];
|
|
const participants = await registry.getParticipants();
|
|
expect(participants).toMatchObject(expectedParticipants);
|
|
});
|
|
};
|
|
|
|
if (process.env.ONBOARDING_ENABLED !== '1') {
|
|
describe('Onboarding disabled', onboardingDisabledTests);
|
|
} else {
|
|
/**
|
|
Running this test requires participants onboarding enabled. In laconicd repo run:
|
|
|
|
ONBOARDING_ENABLED=true ./init.sh
|
|
|
|
Run test:
|
|
|
|
yarn test:onboarding
|
|
*/
|
|
describe('Onboarding enabled', onboardingEnabledTests);
|
|
}
|