From 5735fb56083121cbeaaf12e1306b64778ac02949 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Thu, 25 Jul 2024 17:19:35 +0530 Subject: [PATCH] Accommodate participant role and kyc id and update tests --- src/index.ts | 4 +++- src/laconic-client.ts | 8 ++++++-- src/onboarding.test.ts | 19 ++++++++++++++----- src/registry-client.ts | 2 ++ src/types/cerc/onboarding/message.ts | 3 +++ 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index b3b128e..cf586ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -440,7 +440,7 @@ export class Registry { /** * Onboard participant. */ - async onboardParticipant ({ ethPayload, ethSignature }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee): Promise { + async onboardParticipant ({ ethPayload, ethSignature, role, kycId }: MessageMsgOnboardParticipant, privateKey: string, fee: StdFee): Promise { const account = new Account(Buffer.from(privateKey, 'hex')); await account.init(); const laconicClient = await this.getLaconicClient(account); @@ -449,6 +449,8 @@ export class Registry { account.address, ethPayload, ethSignature, + role, + kycId, fee ); } diff --git a/src/laconic-client.ts b/src/laconic-client.ts index a96b4eb..b11e3ba 100644 --- a/src/laconic-client.ts +++ b/src/laconic-client.ts @@ -22,7 +22,7 @@ import { MsgCommitBidResponse, MsgRevealBidResponse } from './proto/cerc/auction import { MsgCancelBondResponse, MsgCreateBondResponse, MsgRefillBondResponse, MsgWithdrawBondResponse } from './proto/cerc/bond/v1/tx'; import { MsgOnboardParticipantResponse } from './proto/cerc/onboarding/v1/tx'; import { bankTypes } from './types/cosmos/bank/message'; -import { EthPayload } from './proto/cerc/onboarding/v1/onboarding'; +import { EthPayload, Role } from './proto/cerc/onboarding/v1/onboarding'; const DEFAULT_WRITE_ERROR = 'Unable to write to laconicd.'; @@ -394,6 +394,8 @@ export class LaconicClient extends SigningStargateClient { signer: string, ethPayload: EthPayload, ethSignature: string, + role: Role, + kycId: string, fee: StdFee | 'auto' | number, memo = '' ) { @@ -402,7 +404,9 @@ export class LaconicClient extends SigningStargateClient { value: { participant: signer, ethPayload, - ethSignature + ethSignature, + role, + kycId } }; diff --git a/src/onboarding.test.ts b/src/onboarding.test.ts index 3f6ac4b..d67240c 100644 --- a/src/onboarding.test.ts +++ b/src/onboarding.test.ts @@ -4,12 +4,15 @@ import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing'; import { Registry, Account } from './index'; import { getConfig } from './testing/helper'; -import { Participant } from './proto/cerc/onboarding/v1/onboarding'; +import { Participant, Role } from './proto/cerc/onboarding/v1/onboarding'; const { chainId, rpcEndpoint, gqlEndpoint, privateKey, fee } = getConfig(); jest.setTimeout(90 * 1000); +const DUMMY_ROLE = Role.ROLE_VALIDATOR; +const DUMMY_KYC_ID = 'dummyKycId'; + const onboardingEnabledTests = () => { let registry: Registry; let ethWallet: Wallet; @@ -32,7 +35,9 @@ const onboardingEnabledTests = () => { await registry.onboardParticipant({ ethPayload, - ethSignature + ethSignature, + role: DUMMY_ROLE, + kycId: DUMMY_KYC_ID }, privateKey, fee); }); @@ -41,10 +46,12 @@ const onboardingEnabledTests = () => { const cosmosAccount = await DirectSecp256k1Wallet.fromKey(account._privateKey, 'laconic'); const [cosmosWallet] = await cosmosAccount.getAccounts(); - const expectedParticipants = [ + const expectedParticipants: Participant[] = [ { cosmosAddress: cosmosWallet.address, - nitroAddress: ethWallet.address + nitroAddress: ethWallet.address, + role: DUMMY_ROLE, + kycId: DUMMY_KYC_ID } ]; const participants = await registry.getParticipants(); @@ -76,7 +83,9 @@ const onboardingDisabledTests = () => { try { await registry.onboardParticipant({ ethPayload, - ethSignature + ethSignature, + role: DUMMY_ROLE, + kycId: DUMMY_KYC_ID }, privateKey, fee); } catch (error: any) { expect(error.toString()).toContain(errorMsg); diff --git a/src/registry-client.ts b/src/registry-client.ts index bf28a75..5191be2 100644 --- a/src/registry-client.ts +++ b/src/registry-client.ts @@ -426,6 +426,8 @@ export class RegistryClient { getParticipants { cosmosAddress nitroAddress + role + kycId } }`; diff --git a/src/types/cerc/onboarding/message.ts b/src/types/cerc/onboarding/message.ts index edbeccf..369a9b3 100644 --- a/src/types/cerc/onboarding/message.ts +++ b/src/types/cerc/onboarding/message.ts @@ -1,6 +1,7 @@ import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing'; import { MsgOnboardParticipantResponse, MsgOnboardParticipant } from '../../../proto/cerc/onboarding/v1/tx'; +import { Role } from '../../../proto/cerc/onboarding/v1/onboarding'; export const typeUrlMsgOnboardParticipant = '/cerc.onboarding.v1.MsgOnboardParticipant'; export const typeUrlMsgOnboardParticipantResponse = '/cerc.onboarding.v1.MsgOnboardParticipantResponse'; @@ -23,4 +24,6 @@ interface ethPayload { export interface MessageMsgOnboardParticipant { ethPayload: ethPayload ethSignature: string + role: Role + kycId: string }