Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
77 changes: 77 additions & 0 deletions ledger/common/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ type Certificate interface {
isCertificate()
Cbor() []byte
Utxorpc() *utxorpc.Certificate
Type() uint
}

const (
Expand Down Expand Up @@ -177,6 +178,10 @@ func (c *StakeRegistrationCertificate) Utxorpc() *utxorpc.Certificate {
}
}

func (c *StakeRegistrationCertificate) Type() uint {
return c.CertType
}

type StakeDeregistrationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -198,6 +203,10 @@ func (c *StakeDeregistrationCertificate) Utxorpc() *utxorpc.Certificate {
}
}

func (c *StakeDeregistrationCertificate) Type() uint {
return c.CertType
}

type StakeDelegationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -223,6 +232,10 @@ func (c *StakeDelegationCertificate) Utxorpc() *utxorpc.Certificate {
}
}

func (c *StakeDelegationCertificate) Type() uint {
return c.CertType
}

type (
PoolKeyHash Blake2b224
PoolMetadataHash Blake2b256
Expand Down Expand Up @@ -373,6 +386,10 @@ func (c *PoolRegistrationCertificate) Utxorpc() *utxorpc.Certificate {
}
}

func (c *PoolRegistrationCertificate) Type() uint {
return c.CertType
}

type PoolRetirementCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -398,6 +415,10 @@ func (c *PoolRetirementCertificate) Utxorpc() *utxorpc.Certificate {
}
}

func (c *PoolRetirementCertificate) Type() uint {
return c.CertType
}

type GenesisKeyDelegationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand Down Expand Up @@ -425,6 +446,10 @@ func (c *GenesisKeyDelegationCertificate) Utxorpc() *utxorpc.Certificate {
}
}

func (c *GenesisKeyDelegationCertificate) Type() uint {
return c.CertType
}

type MirSource int32

const (
Expand Down Expand Up @@ -508,6 +533,10 @@ func (c *MoveInstantaneousRewardsCertificate) Utxorpc() *utxorpc.Certificate {
}
}

func (c *MoveInstantaneousRewardsCertificate) Type() uint {
return c.CertType
}

type RegistrationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -529,6 +558,10 @@ func (c *RegistrationCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *RegistrationCertificate) Type() uint {
return c.CertType
}

type DeregistrationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -550,6 +583,10 @@ func (c *DeregistrationCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *DeregistrationCertificate) Type() uint {
return c.CertType
}

type VoteDelegationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -571,6 +608,10 @@ func (c *VoteDelegationCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *VoteDelegationCertificate) Type() uint {
return c.CertType
}

type StakeVoteDelegationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -593,6 +634,10 @@ func (c *StakeVoteDelegationCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *StakeVoteDelegationCertificate) Type() uint {
return c.CertType
}

type StakeRegistrationDelegationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -615,6 +660,10 @@ func (c *StakeRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate
return nil
}

func (c *StakeRegistrationDelegationCertificate) Type() uint {
return c.CertType
}

type VoteRegistrationDelegationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -637,6 +686,10 @@ func (c *VoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *VoteRegistrationDelegationCertificate) Type() uint {
return c.CertType
}

type StakeVoteRegistrationDelegationCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -660,6 +713,10 @@ func (c *StakeVoteRegistrationDelegationCertificate) Utxorpc() *utxorpc.Certific
return nil
}

func (c *StakeVoteRegistrationDelegationCertificate) Type() uint {
return c.CertType
}

type AuthCommitteeHotCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -681,6 +738,10 @@ func (c *AuthCommitteeHotCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *AuthCommitteeHotCertificate) Type() uint {
return c.CertType
}

type ResignCommitteeColdCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -702,6 +763,10 @@ func (c *ResignCommitteeColdCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *ResignCommitteeColdCertificate) Type() uint {
return c.CertType
}

type RegistrationDrepCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -724,6 +789,10 @@ func (c *RegistrationDrepCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *RegistrationDrepCertificate) Type() uint {
return c.CertType
}

type DeregistrationDrepCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -745,6 +814,10 @@ func (c *DeregistrationDrepCertificate) Utxorpc() *utxorpc.Certificate {
return nil
}

func (c *DeregistrationDrepCertificate) Type() uint {
return c.CertType
}

type UpdateDrepCertificate struct {
cbor.StructAsArray
cbor.DecodeStoreCbor
Expand All @@ -765,3 +838,7 @@ func (c *UpdateDrepCertificate) Utxorpc() *utxorpc.Certificate {
// TODO (#850)
return nil
}

func (c *UpdateDrepCertificate) Type() uint {
return c.CertType
}
48 changes: 48 additions & 0 deletions ledger/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,51 @@ func TestBlake2b224_String(t *testing.T) {
t.Errorf("expected %s but got %s", expected, hash.String())
}
}

func TestCertificateTypeMethods(t *testing.T) {
tests := []struct {
name string
cert Certificate
expected uint
}{
{"StakeRegistration", &StakeRegistrationCertificate{CertType: CertificateTypeStakeRegistration}, CertificateTypeStakeRegistration},
{"StakeDeregistration", &StakeDeregistrationCertificate{CertType: CertificateTypeStakeDeregistration}, CertificateTypeStakeDeregistration},
{"StakeDelegation", &StakeDelegationCertificate{CertType: CertificateTypeStakeDelegation}, CertificateTypeStakeDelegation},
{"PoolRegistration", &PoolRegistrationCertificate{CertType: CertificateTypePoolRegistration}, CertificateTypePoolRegistration},
{"PoolRetirement", &PoolRetirementCertificate{CertType: CertificateTypePoolRetirement}, CertificateTypePoolRetirement},
{"GenesisKeyDelegation", &GenesisKeyDelegationCertificate{CertType: CertificateTypeGenesisKeyDelegation}, CertificateTypeGenesisKeyDelegation},
{"MoveInstantaneousRewards", &MoveInstantaneousRewardsCertificate{CertType: CertificateTypeMoveInstantaneousRewards}, CertificateTypeMoveInstantaneousRewards},
{"Registration", &RegistrationCertificate{CertType: CertificateTypeRegistration}, CertificateTypeRegistration},
{"Deregistration", &DeregistrationCertificate{CertType: CertificateTypeDeregistration}, CertificateTypeDeregistration},
{"VoteDelegation", &VoteDelegationCertificate{CertType: CertificateTypeVoteDelegation}, CertificateTypeVoteDelegation},
{"StakeVoteDelegation", &StakeVoteDelegationCertificate{CertType: CertificateTypeStakeVoteDelegation}, CertificateTypeStakeVoteDelegation},
{"StakeRegistrationDelegation", &StakeRegistrationDelegationCertificate{CertType: CertificateTypeStakeRegistrationDelegation}, CertificateTypeStakeRegistrationDelegation},
{"VoteRegistrationDelegation", &VoteRegistrationDelegationCertificate{CertType: CertificateTypeVoteRegistrationDelegation}, CertificateTypeVoteRegistrationDelegation},
{"StakeVoteRegistrationDelegation", &StakeVoteRegistrationDelegationCertificate{CertType: CertificateTypeStakeVoteRegistrationDelegation}, CertificateTypeStakeVoteRegistrationDelegation},
{"AuthCommitteeHot", &AuthCommitteeHotCertificate{CertType: CertificateTypeAuthCommitteeHot}, CertificateTypeAuthCommitteeHot},
{"ResignCommitteeCold", &ResignCommitteeColdCertificate{CertType: CertificateTypeResignCommitteeCold}, CertificateTypeResignCommitteeCold},
{"RegistrationDrep", &RegistrationDrepCertificate{CertType: CertificateTypeRegistrationDrep}, CertificateTypeRegistrationDrep},
{"DeregistrationDrep", &DeregistrationDrepCertificate{CertType: CertificateTypeDeregistrationDrep}, CertificateTypeDeregistrationDrep},
{"UpdateDrep", &UpdateDrepCertificate{CertType: CertificateTypeUpdateDrep}, CertificateTypeUpdateDrep},
}

allPassed := true

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.cert.Type()
if got != tt.expected {
allPassed = false
t.Errorf("FAIL: %s -> Type() = %d, expected = %d", tt.name, got, tt.expected)
} else {
t.Logf("PASS: %s -> Type() = %d, expected = %d \n", tt.name, got, tt.expected)
}
})
}

if allPassed {
t.Logf("\n ALL CERTIFICATE TYPE TESTS PASSED SUCCESSFULLY")
} else {
t.Logf("\n SOME CERTIFICATE TYPE TESTS FAILED ")
}
}
Loading