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

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shampoobera committed Jul 4, 2023
1 parent 4878150 commit 29fa996
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 801 deletions.
173 changes: 2 additions & 171 deletions cosmos/precompile/bank/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -709,7 +540,7 @@ var _ = Describe("Bank Precompile Test", func() {
true,
cosmlib.AccAddressToEthAddress(fromAcc),
cosmlib.AccAddressToEthAddress(toAcc),
sdkCoinsToEvmCoins(unsortedSdkCoins),
(unsortedSdkCoins),
)
Expect(err).ToNot(HaveOccurred())

Expand Down Expand Up @@ -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))
})
Expand Down
81 changes: 1 addition & 80 deletions cosmos/precompile/distribution/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 29fa996

Please sign in to comment.