Skip to content
Merged
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
5 changes: 4 additions & 1 deletion packages/tx-construction/src/tx-builder/TxBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Loading