Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

test: add tests staking #1439

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
76 changes: 76 additions & 0 deletions cosmos/precompile/staking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,82 @@
Expect(res[0].OperatorAddr).To(Equal(valAddr))
})
})

When("GetBondedValidatorsByPower", func() {
It("all validator not active", func() {
vals, err := contract.GetBondedValidatorsByPower(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(vals).To(BeEmpty())
})
It("one validator active", func() {
// Set the validator to be bonded.
validator.Status = stakingtypes.Bonded
Expect(sk.SetValidator(ctx, validator)).To(Succeed())

vals, err := contract.GetBondedValidatorsByPower(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(vals).To(HaveLen(1))
})

It("all validator active", func() {
// Set the validator to be bonded.
validator.Status = stakingtypes.Bonded
Expect(sk.SetValidator(ctx, validator)).To(Succeed())

otherValidator.Status = stakingtypes.Bonded
Expect(sk.SetValidator(ctx, otherValidator)).To(Succeed())

vals, err := contract.GetBondedValidatorsByPower(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(vals).To(HaveLen(2))
})
})

When("GetValidators", func() {
It("get all validator without pagination", func() {
vals, _, err := contract.GetValidators(ctx, nil)
Expect(err).ToNot(HaveOccurred())
Expect(len(vals)).To(Equal(2))

Check failure on line 644 in cosmos/precompile/staking/staking_test.go

View workflow job for this annotation

GitHub Actions / ci (lint, polaris-linux-latest, 1.21.6)

ginkgo-linter: wrong length assertion; consider using `Expect(vals).To(HaveLen(2))` instead (ginkgolinter)
})
It("get all validator with pagination", func() {
// Create a pagination request
pagination := cbindings.CosmosPageRequest{
Key: "test",
Offset: 0,
Limit: 10,
CountTotal: true,
Reverse: false,
}
vals, _, err := contract.GetValidators(ctx, pagination)
Expect(err).ToNot(HaveOccurred())
Expect(vals).To(HaveLen(2))
})
})

When("GetValidator", func() {
It("should success when valid validator", func() {
val, err := contract.GetValidator(ctx, valAddr)
Expect(err).ToNot(HaveOccurred())
Expect(val.OperatorAddr).To(Equal(valAddr))
})
It("should error when invalid validator", func() {
_, err := contract.GetValidator(ctx, common.Address{})
Expect(err).To(HaveOccurred())
})
})

When("GetDelegatorValidators", func() {
It("should success", func() {
vals, _, err := contract.GetDelegatorValidators(ctx, caller, nil)
Expect(err).ToNot(HaveOccurred())
Expect(vals).To(HaveLen(1))
})
It("should error when invalid delegator", func() {
vals, _, err := contract.GetDelegatorValidators(ctx, common.Address{}, nil)
Expect(err).ToNot(HaveOccurred())
Expect(vals).To(BeEmpty())
})
})
})
})

Expand Down
Loading