From e7c61f1edae15129a92d4a007fa7a7711ad9acb7 Mon Sep 17 00:00:00 2001 From: vetalcore Date: Thu, 29 May 2025 12:01:25 +0300 Subject: [PATCH] fix: handle ConwayCertsFailure error while buildong portfolio --- .../src/tx-builder/TxBuilder.ts | 5 ++- .../TxBuilderDelegatePortfolio.test.ts | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/tx-construction/src/tx-builder/TxBuilder.ts b/packages/tx-construction/src/tx-builder/TxBuilder.ts index 1bf91d97d17..c9187d0c0aa 100644 --- a/packages/tx-construction/src/tx-builder/TxBuilder.ts +++ b/packages/tx-construction/src/tx-builder/TxBuilder.ts @@ -633,7 +633,10 @@ export class GenericTxBuilder implements TxBuilder { const { id: newPoolId, weight } = newPools.pop()!; const rewardAccount = availableRewardAccounts.pop()!; this.#logger.debug(`Building delegation certificate for ${newPoolId} ${rewardAccount}`); - if (rewardAccount.credentialStatus !== Cardano.StakeCredentialStatus.Registered) { + if ( + rewardAccount.credentialStatus !== Cardano.StakeCredentialStatus.Registered && + rewardAccount.credentialStatus !== Cardano.StakeCredentialStatus.Registering + ) { certificates.push(Cardano.createStakeRegistrationCert(rewardAccount.address)); } certificates.push(Cardano.createDelegationCert(rewardAccount.address, newPoolId)); diff --git a/packages/tx-construction/test/tx-builder/TxBuilderDelegatePortfolio.test.ts b/packages/tx-construction/test/tx-builder/TxBuilderDelegatePortfolio.test.ts index 33bef6de6c3..17eddbf8987 100644 --- a/packages/tx-construction/test/tx-builder/TxBuilderDelegatePortfolio.test.ts +++ b/packages/tx-construction/test/tx-builder/TxBuilderDelegatePortfolio.test.ts @@ -204,6 +204,37 @@ describe('TxBuilder/delegatePortfolio', () => { }); }); + describe('building delegation certificate', () => { + beforeEach(async () => { + const txBuilderFactory = await createTxBuilder({ + keyAgent, + stakeDelegations: [{ credentialStatus: Cardano.StakeCredentialStatus.Registering }] + }); + groupedAddresses = txBuilderFactory.groupedAddresses; + txBuilder = txBuilderFactory.txBuilder; + }); + + it('tx does not contain a stake registration cert', async () => { + const tx = await txBuilder + .delegatePortfolio({ + name: 'Tests Portfolio', + pools: [{ id: Cardano.PoolIdHex(Cardano.PoolId.toKeyHash(poolIds[0])), weight: 1 }] + }) + .build() + .inspect(); + + expect(tx.body.certificates?.length).toBe(1); + expect(tx.body.certificates).toContainEqual({ + __typename: Cardano.CertificateType.StakeDelegation, + poolId: poolIds[0], + stakeCredential: { + hash: Cardano.RewardAccount.toHash(groupedAddresses[0].rewardAccount), + type: Cardano.CredentialType.KeyHash + } + }); + }); + }); + describe('input selection type with multiple reward accounts and single pool delegation', () => { beforeEach(async () => { const txBuilderFactory = await createTxBuilder({