diff --git a/cosmos/precompile/bank/bank_test.go b/cosmos/precompile/bank/bank_test.go index 5b93ac1ef..8b45d4ba0 100644 --- a/cosmos/precompile/bank/bank_test.go +++ b/cosmos/precompile/bank/bank_test.go @@ -137,33 +137,6 @@ var _ = Describe("Bank Precompile Test", func() { denom2 := "atoken" When("GetBalance", func() { - It("should fail if input address is not a common.Address", func() { - res, err := contract.GetBalance( - ctx, - nil, - caller, - big.NewInt(0), - true, - "0x", - "stake", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if input denom is not a valid string", func() { - res, err := contract.GetBalance( - ctx, - nil, - caller, - big.NewInt(0), - true, - cosmlib.AccAddressToEthAddress(acc), - 666, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) It("should fail if input denom is not a valid denom", func() { res, err := contract.GetBalance( @@ -214,18 +187,6 @@ var _ = Describe("Bank Precompile Test", func() { }) When("GetAllBalance", func() { - It("should fail if input address is not a common.Address", func() { - res, err := contract.GetBalance( - ctx, - nil, - caller, - big.NewInt(0), - true, - "0x", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { numOfDenoms := 3 @@ -274,33 +235,6 @@ var _ = Describe("Bank Precompile Test", func() { }) When("GetSpendableBalanceByDenom", func() { - It("should fail if input address is not a common.Address", func() { - res, err := contract.GetSpendableBalance( - ctx, - nil, - caller, - big.NewInt(0), - true, - "0x", - "stake", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if input denom is not a valid string", func() { - res, err := contract.GetSpendableBalance( - ctx, - nil, - caller, - big.NewInt(0), - true, - cosmlib.AccAddressToEthAddress(acc), - 666, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) It("should fail if input denom is not a valid denom", func() { res, err := contract.GetSpendableBalance( @@ -351,18 +285,6 @@ var _ = Describe("Bank Precompile Test", func() { }) When("GetSpendableBalances", func() { - It("should fail if input address is not a common.Address", func() { - res, err := contract.GetAllSpendableBalances( - ctx, - nil, - caller, - big.NewInt(0), - true, - "0x", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { numOfDenoms := 3 @@ -412,18 +334,6 @@ var _ = Describe("Bank Precompile Test", func() { }) When("GetSupplyOf", func() { - It("should fail if input denom is not a valid string", func() { - res, err := contract.GetSupply( - ctx, - nil, - caller, - big.NewInt(0), - true, - 666, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) It("should fail if input denom is not a valid Denom", func() { res, err := contract.GetSupply( @@ -521,18 +431,6 @@ var _ = Describe("Bank Precompile Test", func() { }) When("GetDenomMetadata", func() { - It("should fail if input denom is not a valid string", func() { - res, err := contract.GetDenomMetadata( - ctx, - nil, - caller, - big.NewInt(0), - true, - 666, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) It("should fail if input denom is not a valid Denom", func() { res, err := contract.GetDenomMetadata( @@ -600,73 +498,6 @@ var _ = Describe("Bank Precompile Test", func() { }) When("Send", func() { - It("should fail if from address is not a common.Address", func() { - balanceAmount, ok := new(big.Int).SetString("22000000000000000000", 10) - Expect(ok).To(BeTrue()) - - acc = simtestutil.CreateRandomAccounts(1)[0] - - res, err := contract.Send( - ctx, - nil, - caller, - big.NewInt(0), - true, - "0x", - cosmlib.AccAddressToEthAddress(acc), - sdk.NewCoins( - sdk.NewCoin( - denom, - sdkmath.NewIntFromBigInt(balanceAmount), - ), - ), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if to address is not a common.Address", func() { - balanceAmount, ok := new(big.Int).SetString("22000000000000000000", 10) - Expect(ok).To(BeTrue()) - - acc = simtestutil.CreateRandomAccounts(1)[0] - - res, err := contract.Send( - ctx, - nil, - caller, - big.NewInt(0), - true, - cosmlib.AccAddressToEthAddress(acc), - "0x", - sdk.NewCoins( - sdk.NewCoin( - denom, - sdkmath.NewIntFromBigInt(balanceAmount), - ), - ), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if amount is not sdk.Coins", func() { - accs := simtestutil.CreateRandomAccounts(2) - fromAcc, toAcc := accs[0], accs[1] - - res, err := contract.Send( - ctx, - nil, - caller, - big.NewInt(0), - true, - cosmlib.AccAddressToEthAddress(fromAcc), - cosmlib.AccAddressToEthAddress(toAcc), - "wrong type input", - ) - Expect(err).To(MatchError(precompile.ErrInvalidCoin)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { balanceAmount, ok := new(big.Int).SetString("220000000000000000", 10) @@ -709,7 +540,7 @@ var _ = Describe("Bank Precompile Test", func() { true, cosmlib.AccAddressToEthAddress(fromAcc), cosmlib.AccAddressToEthAddress(toAcc), - sdkCoinsToEvmCoins(unsortedSdkCoins), + (unsortedSdkCoins), ) Expect(err).ToNot(HaveOccurred()) @@ -746,7 +577,7 @@ var _ = Describe("Bank Precompile Test", func() { true, cosmlib.AccAddressToEthAddress(fromAcc), cosmlib.AccAddressToEthAddress(toAcc), - sdkCoinsToEvmCoins(coinsToSend), + (coinsToSend), ) Expect(err).To(MatchError(precompile.ErrInvalidCoin)) }) diff --git a/cosmos/precompile/distribution/distribution_test.go b/cosmos/precompile/distribution/distribution_test.go index bbfc342f8..6ca388736 100644 --- a/cosmos/precompile/distribution/distribution_test.go +++ b/cosmos/precompile/distribution/distribution_test.go @@ -44,7 +44,6 @@ import ( libgenerated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/lib" cosmlib "pkg.berachain.dev/polaris/cosmos/lib" - "pkg.berachain.dev/polaris/cosmos/precompile" testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" "pkg.berachain.dev/polaris/cosmos/x/evm/plugins/precompile/log" ethprecompile "pkg.berachain.dev/polaris/eth/core/precompile" @@ -144,18 +143,6 @@ var _ = Describe("Distribution Precompile Test", func() { }) When("SetWithdrawAddress", func() { - It("should fail if not common address", func() { - res, err := contract.SetWithdrawAddress( - ctx, - nil, - testutil.Alice, - big.NewInt(0), - false, - "invalid", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { res, err := contract.SetWithdrawAddress( @@ -172,18 +159,6 @@ var _ = Describe("Distribution Precompile Test", func() { }) When("SetWithdrawAddressBech32", func() { - It("should fail if not string", func() { - res, err := contract.SetWithdrawAddress0( - ctx, - nil, - testutil.Alice, - big.NewInt(0), - false, - 1, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) It("should fail if not bech32 string", func() { res, err := contract.SetWithdrawAddress0( @@ -269,33 +244,6 @@ var _ = Describe("Distribution Precompile Test", func() { }) When("Withdraw Delegator Rewards common address", func() { - It("should fail if not common address", func() { - res, err := contract.WithdrawDelegatorReward( - ctx, - nil, - testutil.Alice, - big.NewInt(0), - false, - "0x0000000000", - cosmlib.ValAddressToEthAddress(valAddr), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if validator address not common.address", func() { - res, err := contract.WithdrawDelegatorReward( - ctx, - nil, - testutil.Alice, - big.NewInt(0), - false, - cosmlib.AccAddressToEthAddress(addr), - "0x0000000000", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) It("Success", func() { res, err := contract.WithdrawDelegatorReward( @@ -316,35 +264,8 @@ var _ = Describe("Distribution Precompile Test", func() { }) When("Withdraw Delegator Rewards bech32 address", func() { - It("should fail if delegator address not string", func() { - res, err := contract.WithdrawDelegatorReward0( - ctx, - nil, - testutil.Alice, - big.NewInt(0), - false, - 1, - valAddr.String(), - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should fail if validator address not string", func() { - res, err := contract.WithdrawDelegatorReward0( - ctx, - nil, - testutil.Alice, - big.NewInt(0), - false, - addr.String(), - 1, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - It("should fail if delegator address not bech32", func() { + FIt("should fail if delegator address not bech32", func() { res, err := contract.WithdrawDelegatorReward0( ctx, nil, diff --git a/cosmos/precompile/governance/governance_test.go b/cosmos/precompile/governance/governance_test.go index cf84f7e3e..ceda4a2b2 100644 --- a/cosmos/precompile/governance/governance_test.go +++ b/cosmos/precompile/governance/governance_test.go @@ -43,7 +43,6 @@ import ( . "github.com/onsi/gomega" generated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/precompile/governance" cosmlib "pkg.berachain.dev/polaris/cosmos/lib" - "pkg.berachain.dev/polaris/cosmos/precompile" precomtest "pkg.berachain.dev/polaris/cosmos/precompile/test" testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" "pkg.berachain.dev/polaris/cosmos/types" @@ -123,31 +122,7 @@ var _ = Describe("Governance Precompile", func() { }) When("Submitting a proposal", func() { - It("Should fail if proposal is of wrong type", func() { - res, err := contract.SubmitProposal( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - "invalid", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBytes)) - Expect(res).To(BeNil()) - }) - It("Should fail if the message is of wrong type", func() { - res, err := contract.SubmitProposal( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - []byte{}, - "invalid", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBytes)) - Expect(res).To(BeNil()) - }) + It("should succeed", func() { initDeposit := sdk.NewCoins(sdk.NewInt64Coin("abera", 100)) govAcct := gk.GetGovernanceAccount(ctx).GetAddress() @@ -193,30 +168,6 @@ var _ = Describe("Governance Precompile", func() { }) When("Canceling a proposal", func() { - It("should fail if the proposal ID is invalid", func() { - res, err := contract.CancelProposal( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - "invalid", - ) - Expect(err).To(MatchError(precompile.ErrInvalidUint64)) - Expect(res).To(BeNil()) - }) - It("should fail if the proposal does not exist", func() { - res, err := contract.CancelProposal( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - big.NewInt(1), - ) - Expect(err).To(HaveOccurred()) - Expect(res).To(BeNil()) - }) It("should succeed", func() { err := gk.SetProposal(ctx, v1.Proposal{ Id: 1, @@ -249,48 +200,7 @@ var _ = Describe("Governance Precompile", func() { }) Expect(err).ToNot(HaveOccurred()) }) - It("should fail if the proposal ID is of invalid type", func() { - res, err := contract.Vote( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - "invalid", - int32(1), - "metadata", - ) - Expect(err).To(MatchError(precompile.ErrInvalidUint64)) - Expect(res).To(BeNil()) - }) - It("should fail if the vote option is of invalid type", func() { - res, err := contract.Vote( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - uint64(1), - "invalid", - "metadata", - ) - Expect(err).To(MatchError(precompile.ErrInvalidInt32)) - Expect(res).To(BeNil()) - }) - It("should fail if the metadata is of invalid type", func() { - res, err := contract.Vote( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - uint64(1), - int32(1), - 123, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) + It("should fail if the proposal does not exist", func() { res, err := contract.Vote( ctx, @@ -321,48 +231,7 @@ var _ = Describe("Governance Precompile", func() { }) When("Voting Weight", func() { - It("should fail if the proposal ID is of invalid type", func() { - res, err := contract.VoteWeighted( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - "invalid", - []generated.IGovernanceModuleWeightedVoteOption{}, - "metadata", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) - It("should fail if the vote option is of invalid type", func() { - res, err := contract.VoteWeighted( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - uint64(1), - 12, - "metadata", - ) - Expect(err).To(MatchError(precompile.ErrInvalidOptions)) - Expect(res).To(BeNil()) - }) - It("should fail if the metadata is of invalid type", func() { - res, err := contract.VoteWeighted( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - uint64(1), - []generated.IGovernanceModuleWeightedVoteOption{}, - 123, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) + It("should fail if the proposal does not exist", func() { res, err := contract.VoteWeighted( ctx, @@ -440,18 +309,6 @@ var _ = Describe("Governance Precompile", func() { }) When("GetProposal", func() { - It("should fail if the proposal ID is of invalid type", func() { - res, err := contract.GetProposal( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - "invalid", - ) - Expect(err).To(MatchError(precompile.ErrInvalidUint64)) - Expect(res).To(BeNil()) - }) It("should get the proposal", func() { res, err := contract.GetProposal( ctx, @@ -472,18 +329,6 @@ var _ = Describe("Governance Precompile", func() { _, err := contract.CancelProposal(ctx, nil, common.Address(caller), big.NewInt(0), false, uint64(1)) Expect(err).ToNot(HaveOccurred()) }) - It("should fail if the status is of invalid type", func() { - res, err := contract.GetProposals( - ctx, - nil, - cosmlib.AccAddressToEthAddress(caller), - big.NewInt(0), - false, - "", - ) - Expect(err).To(MatchError(precompile.ErrInvalidInt32)) - Expect(res).To(BeNil()) - }) It("should get the proposals", func() { res, err := contract.GetProposals( ctx, diff --git a/cosmos/precompile/staking/staking.go b/cosmos/precompile/staking/staking.go index f0251db2c..75aa97301 100644 --- a/cosmos/precompile/staking/staking.go +++ b/cosmos/precompile/staking/staking.go @@ -31,10 +31,8 @@ import ( generated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/precompile/staking" cosmlib "pkg.berachain.dev/polaris/cosmos/lib" - "pkg.berachain.dev/polaris/cosmos/precompile" "pkg.berachain.dev/polaris/eth/common" ethprecompile "pkg.berachain.dev/polaris/eth/core/precompile" - "pkg.berachain.dev/polaris/lib/utils" ) // Contract is the precompile contract for the staking module. @@ -134,19 +132,11 @@ func (c *Contract) GetDelegation( _ common.Address, _ *big.Int, _ bool, - args ...any, + delegatorAddress common.Address, + validatorAddress common.Address, ) ([]any, error) { - del, ok := utils.GetAs[common.Address](args[0]) - if !ok { - return nil, precompile.ErrInvalidHexAddress - } - val, ok := utils.GetAs[common.Address](args[1]) - if !ok { - return nil, precompile.ErrInvalidHexAddress - } - return c.getDelegationHelper( - ctx, cosmlib.AddressToAccAddress(del), cosmlib.AddressToValAddress(val), + ctx, cosmlib.AddressToAccAddress(delegatorAddress), cosmlib.AddressToValAddress(validatorAddress), ) } diff --git a/cosmos/precompile/staking/staking_test.go b/cosmos/precompile/staking/staking_test.go index 3cde3c322..0ef9f37c6 100644 --- a/cosmos/precompile/staking/staking_test.go +++ b/cosmos/precompile/staking/staking_test.go @@ -37,7 +37,6 @@ import ( . "github.com/onsi/gomega" generated "pkg.berachain.dev/polaris/contracts/bindings/cosmos/precompile/staking" cosmlib "pkg.berachain.dev/polaris/cosmos/lib" - "pkg.berachain.dev/polaris/cosmos/precompile" testutil "pkg.berachain.dev/polaris/cosmos/testing/utils" "pkg.berachain.dev/polaris/eth/accounts/abi" "pkg.berachain.dev/polaris/eth/common" @@ -156,32 +155,6 @@ var _ = Describe("Staking", func() { }) When("Delegate", func() { - It("should fail if input is not a common.Address", func() { - res, err := contract.Delegate( - ctx, - nil, - caller, - big.NewInt(0), - true, - "0x", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.Delegate( - ctx, - nil, - caller, - big.NewInt(0), - true, - cosmlib.ValAddressToEthAddress(val), - "amount", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { amountToDelegate, ok := new(big.Int).SetString("22000000000000000000", 10) @@ -211,28 +184,6 @@ var _ = Describe("Staking", func() { }) When("Delegate0", func() { - It("should fail if input is not a string", func() { - res, err := contract.Delegate0( - ctx, nil, caller, - big.NewInt(0), - false, - 90909, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.Delegate0( - ctx, nil, caller, - big.NewInt(0), - false, - val.String(), - "amount", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) It("should fail if the string is not a valid address", func() { res, err := contract.Delegate0( @@ -276,27 +227,6 @@ var _ = Describe("Staking", func() { }) When("GetDelegation", func() { - It("should return an error if the input del is not a common.Address", func() { - res, err := contract.GetDelegation( - ctx, nil, caller, - big.NewInt(0), - true, - "0x", cosmlib.ValAddressToEthAddress(val), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should return an error if the val address is not common.address", func() { - res, err := contract.GetDelegation( - ctx, nil, caller, - big.NewInt(0), - true, - cosmlib.AccAddressToEthAddress(del), "0x", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) It("should return the correct delegation", func() { res, err := contract.GetDelegation( @@ -311,27 +241,6 @@ var _ = Describe("Staking", func() { }) When("GetDelegation0", func() { - It("should error if not string", func() { - res, err := contract.GetDelegation0( - ctx, nil, caller, - big.NewInt(0), - true, - 0, val.String(), - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should error if the val address is not a string", func() { - res, err := contract.GetDelegation0( - ctx, nil, caller, - big.NewInt(0), - true, - del.String(), 0, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) It("should error if del not bech32", func() { res, err := contract.GetDelegation0( @@ -368,29 +277,6 @@ var _ = Describe("Staking", func() { }) When("Undelegate", func() { - It("should fail if the input is not a common.Address", func() { - res, err := contract.Undelegate( - ctx, nil, caller, - big.NewInt(0), - true, - "0x", - big.NewInt(0), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.Undelegate( - ctx, nil, caller, - big.NewInt(0), - true, - cosmlib.ValAddressToEthAddress(val), - "amount", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { _, err := contract.Undelegate( @@ -405,30 +291,6 @@ var _ = Describe("Staking", func() { }) When("Undelegate0", func() { - It("should fail if the input is not a string", func() { - res, err := contract.Undelegate0( - ctx, nil, caller, - big.NewInt(0), - true, - 90909, - big.NewInt(0), - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.Undelegate0( - ctx, nil, caller, - big.NewInt(0), - true, - val.String(), - "amount", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) - It("should fail if the address is not of type bech32", func() { res, err := contract.Undelegate0( ctx, nil, caller, @@ -454,44 +316,6 @@ var _ = Describe("Staking", func() { }) When("BeginRedelegations", func() { - It("should fail if the srcValue is not a common.Address", func() { - res, err := contract.BeginRedelegate( - ctx, nil, caller, - big.NewInt(0), - false, - 10, - cosmlib.ValAddressToEthAddress(val), - big.NewInt(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if the dstValue is not a common.Address", func() { - res, err := contract.BeginRedelegate( - ctx, nil, caller, - big.NewInt(0), - false, - cosmlib.ValAddressToEthAddress(val), - 10, - big.NewInt(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.BeginRedelegate( - ctx, nil, caller, - big.NewInt(0), - false, - cosmlib.ValAddressToEthAddress(val), - cosmlib.ValAddressToEthAddress(val), - "amount", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { _, err := contract.BeginRedelegate( @@ -507,44 +331,6 @@ var _ = Describe("Staking", func() { }) When("BeginRedelegations0", func() { - It("should fail if the srcValue is not a string", func() { - res, err := contract.BeginRedelegate0( - ctx, nil, caller, - big.NewInt(0), - false, - 10, - val.String(), - big.NewInt(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should fail if the dstValue is not a string", func() { - res, err := contract.BeginRedelegate0( - ctx, nil, caller, - big.NewInt(0), - false, - val.String(), - 10, - big.NewInt(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.BeginRedelegate0( - ctx, nil, caller, - big.NewInt(0), - false, - val.String(), - otherVal.String(), - "amount", - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) It("should fail if the srcValue is not of type bech32", func() { res, err := contract.BeginRedelegate0( @@ -586,45 +372,6 @@ var _ = Describe("Staking", func() { }) When("CancelUnbondingDelegation", func() { - It("should fail if the address is not a common.Address", func() { - res, err := contract.CancelUnbondingDelegation( - ctx, nil, caller, - big.NewInt(0), - false, - "cosmlib.ValAddressToEthAddress(val)", - big.NewInt(1), - int64(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.CancelUnbondingDelegation( - ctx, nil, caller, - big.NewInt(0), - false, - cosmlib.ValAddressToEthAddress(val), - "amount", - int64(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) - - It("should fail if creation height is not an int64", func() { - res, err := contract.CancelUnbondingDelegation( - ctx, nil, caller, - big.NewInt(0), - false, - cosmlib.ValAddressToEthAddress(val), - big.NewInt(1), - "height", - ) - Expect(err).To(MatchError(precompile.ErrInvalidInt64)) - Expect(res).To(BeNil()) - }) - It("should succeed", func() { creationHeight := ctx.BlockHeight() amount, ok := new(big.Int).SetString("1", 10) @@ -653,44 +400,6 @@ var _ = Describe("Staking", func() { }) When("CancelUnbondingDelegation0", func() { - It("should fail if the address is not a string", func() { - res, err := contract.CancelUnbondingDelegation0( - ctx, nil, caller, - big.NewInt(0), - false, - 10, - big.NewInt(1), - int64(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should fail if the amount is not a *big.Int", func() { - res, err := contract.CancelUnbondingDelegation0( - ctx, nil, caller, - big.NewInt(0), - false, - val.String(), - "amount", - int64(1), - ) - Expect(err).To(MatchError(precompile.ErrInvalidBigInt)) - Expect(res).To(BeNil()) - }) - - It("should fail if creation height is not an int64", func() { - res, err := contract.CancelUnbondingDelegation0( - ctx, nil, caller, - big.NewInt(0), - false, - val.String(), - big.NewInt(1), - "height", - ) - Expect(err).To(MatchError(precompile.ErrInvalidInt64)) - Expect(res).To(BeNil()) - }) It("should fail if the address is not a bech32 address", func() { res, err := contract.CancelUnbondingDelegation0( @@ -733,17 +442,6 @@ var _ = Describe("Staking", func() { }) When("GetUnbondingDelegation", func() { - It("should fail if address is not a common.Address", func() { - res, err := contract.GetUnbondingDelegation( - ctx, nil, caller, - big.NewInt(0), - true, - caller, - "cosmlib.ValAddressToEthAddress(val)", - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) It("should succeed", func() { // Undelegate. @@ -771,27 +469,6 @@ var _ = Describe("Staking", func() { }) When("GetUnbondingDelegation0", func() { - It("should fail if address is not a string", func() { - res, err := contract.GetUnbondingDelegation0( - ctx, nil, caller, - big.NewInt(0), - true, - 10, - ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) - - It("should fail if address is not a bech32 address", func() { - res, err := contract.GetUnbondingDelegation0( - ctx, nil, caller, - big.NewInt(0), - true, - "0x", - ) - Expect(err).To(HaveOccurred()) - Expect(res).To(BeNil()) - }) It("should succeed", func() { // Undelegate. @@ -819,83 +496,70 @@ var _ = Describe("Staking", func() { }) When("GetRedelegations", func() { - It("should fail if address is not a common.Address", func() { - res, err := contract.GetRedelegations( - ctx, nil, caller, - big.NewInt(0), - true, - caller, - "cosmlib.ValAddressToEthAddress(val)", - cosmlib.ValAddressToEthAddress(val), - ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) + FIt("should succeed", func() { - It("should fail if dst address is not a common.Address", func() { - res, err := contract.GetRedelegations( - ctx, nil, caller, - big.NewInt(0), - true, - cosmlib.ValAddressToEthAddress(val), - "cosmlib.ValAddressToEthAddress(val)", + amount, ok := new(big.Int).SetString("220000000000000000000", 10) + Expect(ok).To(BeTrue()) + + err := FundAccount( + ctx, + bk, + cosmlib.AddressToAccAddress(caller), + sdk.NewCoins( + sdk.NewCoin( + "stake", + sdkmath.NewIntFromBigInt(amount), + ), + ), ) - Expect(err).To(MatchError(precompile.ErrInvalidHexAddress)) - Expect(res).To(BeNil()) - }) - }) + Expect(err).ToNot(HaveOccurred()) - When("GetRedelegations0", func() { - It("should fail if src address is not a string", func() { - res, err := contract.GetRedelegations0( + ret, err := contract.Delegate( ctx, nil, caller, big.NewInt(0), true, - 10, - otherVal.String(), + cosmlib.ValAddressToEthAddress(val), + amount, ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) + Expect(utils.MustGetAs[bool](ret[0])).To(BeTrue()) + Expect(err).ToNot(HaveOccurred()) - It("should fail if dst address is not a string", func() { - res, err := contract.GetRedelegations0( - ctx, nil, caller, + ret, err = contract.BeginRedelegate( + ctx, + nil, + caller, big.NewInt(0), - true, - val.String(), - 10, + false, + cosmlib.ValAddressToEthAddress(val), + cosmlib.ValAddressToEthAddress(otherVal), + amount, ) - Expect(err).To(MatchError(precompile.ErrInvalidString)) - Expect(res).To(BeNil()) - }) + Expect(utils.MustGetAs[bool](ret[0])).To(BeTrue()) + Expect(err).ToNot(HaveOccurred()) - It("should fail if src address is not a bech32 address", func() { - res, err := contract.GetRedelegations0( - ctx, nil, caller, + ret, err = contract.GetDelegation(ctx, nil, caller, big.NewInt(0), true, - cosmlib.AddressToAccAddress(caller).String(), - "0x", - otherVal.String(), + caller, + cosmlib.ValAddressToEthAddress(otherVal), ) - Expect(err).To(HaveOccurred()) - Expect(res).To(BeNil()) - }) + Expect(err).ToNot(HaveOccurred()) + Expect(utils.MustGetAs[*big.Int](ret[0]).Cmp(amount)).To(Equal(0)) - It("should fail if dst address is not a bech32 address", func() { - res, err := contract.GetRedelegations0( + ret, err = contract.GetRedelegations( ctx, nil, caller, big.NewInt(0), true, - cosmlib.AddressToAccAddress(caller).String(), - val.String(), - "0x", + caller, + cosmlib.ValAddressToEthAddress(val), + cosmlib.ValAddressToEthAddress(otherVal), ) - Expect(err).To(HaveOccurred()) - Expect(res).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) + Expect(ret).ToNot(BeNil()) }) + }) + When("GetRedelegations0", func() { When("Calling Helper Methods", func() { When("delegationHelper", func() { It("should fail if the del address is not valid", func() {