Skip to content

Commit

Permalink
fix(core): fix invalid serialization of stakeVoteDelegation certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
mchappell committed Nov 28, 2023
1 parent 06c2840 commit cebf485
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class Certificate {
certificate = Certificate.newVoteDelegationCert(VoteDelegation.fromCbor(cbor));
break;
case CertificateKind.StakeVoteDelegation:
certificate = Certificate.newStakeDelegation(StakeDelegation.fromCbor(cbor));
certificate = Certificate.newStakeVoteDelegationCert(StakeVoteDelegation.fromCbor(cbor));
break;
case CertificateKind.StakeRegistrationDelegation:
certificate = Certificate.newStakeRegistrationDelegationCert(StakeRegistrationDelegation.fromCbor(cbor));
Expand Down
103 changes: 103 additions & 0 deletions packages/core/test/Serialization/Certificates/Certificate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,107 @@ describe('Certificate', () => {
});
});
});

describe('StakeVoteDelegation', () => {
it('can decode StakeVoteDelegation from CBOR', () => {
const cbor = HexBlob(
'840a8200581c00000000000000000000000000000000000000000000000000000000581c000000000000000000000000000000000000000000000000000000008200581c00000000000000000000000000000000000000000000000000000000'
);

const certificate = Certificate.fromCbor(cbor);

expect(certificate.asMoveInstantaneousRewardsCert()).toBeUndefined();
expect(certificate.asPoolRetirement()).toBeUndefined();
expect(certificate.asPoolRegistration()).toBeUndefined();
expect(certificate.asStakeRegistration()).toBeUndefined();
expect(certificate.asStakeDeregistration()).toBeUndefined();
expect(certificate.asStakeDelegation()).toBeUndefined();
expect(certificate.asStakeVoteDelegationCert()!.drep().toKeyHash()).toEqual(
'00000000000000000000000000000000000000000000000000000000'
);
expect(certificate.asStakeVoteDelegationCert()!.stakeCredential().hash).toEqual(
'00000000000000000000000000000000000000000000000000000000'
);
expect(certificate.asStakeVoteDelegationCert()!.poolKeyHash()).toEqual(
'00000000000000000000000000000000000000000000000000000000'
);
});

it('can decode StakeVoteDelegation from Core', () => {
const core: Cardano.StakeVoteDelegationCertificate = {
__typename: Cardano.CertificateType.StakeVoteDelegation,
dRep: {
hash: '00000000000000000000000000000000000000000000000000000000',
type: 0
},
poolId: 'pool1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8a7a2d',
stakeCredential: {
hash: Crypto.Hash28ByteBase16('00000000000000000000000000000000000000000000000000000000'),
type: Cardano.CredentialType.KeyHash
}
} as Cardano.StakeVoteDelegationCertificate;

const certificate = Certificate.fromCore(core);

expect(certificate.asMoveInstantaneousRewardsCert()).toBeUndefined();
expect(certificate.asPoolRetirement()).toBeUndefined();
expect(certificate.asPoolRegistration()).toBeUndefined();
expect(certificate.asStakeRegistration()).toBeUndefined();
expect(certificate.asStakeDeregistration()).toBeUndefined();
expect(certificate.asStakeDelegation()).toBeUndefined();
expect(certificate.asStakeVoteDelegationCert()!.drep().toCore()).toEqual({
hash: '00000000000000000000000000000000000000000000000000000000',
type: 0
});
expect(certificate.asStakeVoteDelegationCert()!.stakeCredential()).toEqual({
hash: '00000000000000000000000000000000000000000000000000000000',
type: 0
});
expect(certificate.asStakeVoteDelegationCert()!.poolKeyHash()).toEqual(
'00000000000000000000000000000000000000000000000000000000'
);
});

it('can encode StakeVoteDelegation to CBOR', () => {
const core: Cardano.StakeVoteDelegationCertificate = {
__typename: Cardano.CertificateType.StakeVoteDelegation,
dRep: {
hash: '00000000000000000000000000000000000000000000000000000000',
type: 0
},
poolId: 'pool1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8a7a2d',
stakeCredential: {
hash: Crypto.Hash28ByteBase16('00000000000000000000000000000000000000000000000000000000'),
type: Cardano.CredentialType.KeyHash
}
} as Cardano.StakeVoteDelegationCertificate;

const certificate = Certificate.fromCore(core);

expect(certificate.toCbor()).toEqual(
'840a8200581c00000000000000000000000000000000000000000000000000000000581c000000000000000000000000000000000000000000000000000000008200581c00000000000000000000000000000000000000000000000000000000'
);
});

it('can encode StakeVoteDelegation to Core', () => {
const cbor = HexBlob(
'840a8200581c00000000000000000000000000000000000000000000000000000000581c000000000000000000000000000000000000000000000000000000008200581c00000000000000000000000000000000000000000000000000000000'
);

const certificate = Certificate.fromCbor(cbor);

expect(certificate.toCore()).toEqual({
__typename: Cardano.CertificateType.StakeVoteDelegation,
dRep: {
hash: '00000000000000000000000000000000000000000000000000000000',
type: 0
},
poolId: 'pool1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq8a7a2d',
stakeCredential: {
hash: Crypto.Hash28ByteBase16('00000000000000000000000000000000000000000000000000000000'),
type: Cardano.CredentialType.KeyHash
}
});
});
});
});

0 comments on commit cebf485

Please sign in to comment.