Skip to content

Commit e7c61f1

Browse files
committed
fix: handle ConwayCertsFailure error while buildong portfolio
1 parent b01e2b8 commit e7c61f1

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/tx-construction/src/tx-builder/TxBuilder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,10 @@ export class GenericTxBuilder implements TxBuilder {
633633
const { id: newPoolId, weight } = newPools.pop()!;
634634
const rewardAccount = availableRewardAccounts.pop()!;
635635
this.#logger.debug(`Building delegation certificate for ${newPoolId} ${rewardAccount}`);
636-
if (rewardAccount.credentialStatus !== Cardano.StakeCredentialStatus.Registered) {
636+
if (
637+
rewardAccount.credentialStatus !== Cardano.StakeCredentialStatus.Registered &&
638+
rewardAccount.credentialStatus !== Cardano.StakeCredentialStatus.Registering
639+
) {
637640
certificates.push(Cardano.createStakeRegistrationCert(rewardAccount.address));
638641
}
639642
certificates.push(Cardano.createDelegationCert(rewardAccount.address, newPoolId));

packages/tx-construction/test/tx-builder/TxBuilderDelegatePortfolio.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,37 @@ describe('TxBuilder/delegatePortfolio', () => {
204204
});
205205
});
206206

207+
describe('building delegation certificate', () => {
208+
beforeEach(async () => {
209+
const txBuilderFactory = await createTxBuilder({
210+
keyAgent,
211+
stakeDelegations: [{ credentialStatus: Cardano.StakeCredentialStatus.Registering }]
212+
});
213+
groupedAddresses = txBuilderFactory.groupedAddresses;
214+
txBuilder = txBuilderFactory.txBuilder;
215+
});
216+
217+
it('tx does not contain a stake registration cert', async () => {
218+
const tx = await txBuilder
219+
.delegatePortfolio({
220+
name: 'Tests Portfolio',
221+
pools: [{ id: Cardano.PoolIdHex(Cardano.PoolId.toKeyHash(poolIds[0])), weight: 1 }]
222+
})
223+
.build()
224+
.inspect();
225+
226+
expect(tx.body.certificates?.length).toBe(1);
227+
expect(tx.body.certificates).toContainEqual({
228+
__typename: Cardano.CertificateType.StakeDelegation,
229+
poolId: poolIds[0],
230+
stakeCredential: {
231+
hash: Cardano.RewardAccount.toHash(groupedAddresses[0].rewardAccount),
232+
type: Cardano.CredentialType.KeyHash
233+
}
234+
});
235+
});
236+
});
237+
207238
describe('input selection type with multiple reward accounts and single pool delegation', () => {
208239
beforeEach(async () => {
209240
const txBuilderFactory = await createTxBuilder({

0 commit comments

Comments
 (0)