forked from evmos/evmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp(stride): Transactions implementation and events unit tests (evmos…
…#1932) * chore(stride): Add stride outpost unit testing setup * fix: add the registering in the setup * CHANGELOG * imp(stride): Transaction implementations and events unit tests * fix: add custom errors * CHANGELOG * fix: fix linter issues * fix: add license to errors file * fix: slim down test boilerplate * run make format * Apply suggestions from code review Co-authored-by: stepit <[email protected]> --------- Co-authored-by: Vvaradinov <[email protected]> Co-authored-by: stepit <[email protected]>
- Loading branch information
1 parent
fa43a10
commit 6d4b9cc
Showing
7 changed files
with
337 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright Tharsis Labs Ltd.(Evmos) | ||
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/evmos/blob/main/LICENSE) | ||
|
||
package stride | ||
|
||
const ( | ||
// ErrTokenPairNotFound is the error returned when a token pair is not found | ||
// #nosec G101 | ||
ErrTokenPairNotFound = "token pair not found for %s" | ||
// ErrUnsupportedToken is the error returned when a token is not supported | ||
ErrUnsupportedToken = "unsupported token %s. The only supported token contract for Stride Outpost v1 is %s" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package stride_test | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
cmn "github.com/evmos/evmos/v15/precompiles/common" | ||
"github.com/evmos/evmos/v15/precompiles/outposts/stride" | ||
"github.com/evmos/evmos/v15/utils" | ||
) | ||
|
||
const receiver = "stride1rhe5leyt5w0mcwd9rpp93zqn99yktsxvyaqgd0" | ||
|
||
func (s *PrecompileTestSuite) TestLiquidStakeEvent() { | ||
denomID := s.app.Erc20Keeper.GetDenomMap(s.ctx, utils.BaseDenom) | ||
tokenPair, ok := s.app.Erc20Keeper.GetTokenPair(s.ctx, denomID) | ||
s.Require().True(ok, "expected token pair to be found") | ||
|
||
//nolint:dupl | ||
testCases := []struct { | ||
name string | ||
postCheck func() | ||
}{ | ||
{ | ||
"success", | ||
func() { | ||
liquidStakeLog := s.stateDB.Logs()[0] | ||
s.Require().Equal(liquidStakeLog.Address, s.precompile.Address()) | ||
// Check event signature matches the one emitted | ||
event := s.precompile.ABI.Events[stride.EventTypeLiquidStake] | ||
s.Require().Equal(event.ID, common.HexToHash(liquidStakeLog.Topics[0].Hex())) | ||
s.Require().Equal(liquidStakeLog.BlockNumber, uint64(s.ctx.BlockHeight())) | ||
|
||
var liquidStakeEvent stride.EventLiquidStake | ||
err := cmn.UnpackLog(s.precompile.ABI, &liquidStakeEvent, stride.EventTypeLiquidStake, *liquidStakeLog) | ||
s.Require().NoError(err) | ||
s.Require().Equal(common.BytesToAddress(s.address.Bytes()), liquidStakeEvent.Sender) | ||
s.Require().Equal(common.HexToAddress(tokenPair.Erc20Address), liquidStakeEvent.Token) | ||
s.Require().Equal(big.NewInt(1e18), liquidStakeEvent.Amount) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
s.SetupTest() | ||
|
||
err := s.precompile.EmitLiquidStakeEvent(s.ctx, s.stateDB, s.address, common.HexToAddress(tokenPair.Erc20Address), big.NewInt(1e18)) | ||
s.Require().NoError(err) | ||
tc.postCheck() | ||
}) | ||
} | ||
} | ||
|
||
func (s *PrecompileTestSuite) TestRedeemEvent() { | ||
bondDenom := s.app.StakingKeeper.BondDenom(s.ctx) | ||
denomTrace := transfertypes.DenomTrace{ | ||
Path: fmt.Sprintf("%s/%s", portID, channelID), | ||
BaseDenom: "st" + bondDenom, | ||
} | ||
|
||
stEvmos := denomTrace.IBCDenom() | ||
|
||
denomID := s.app.Erc20Keeper.GetDenomMap(s.ctx, stEvmos) | ||
tokenPair, ok := s.app.Erc20Keeper.GetTokenPair(s.ctx, denomID) | ||
s.Require().True(ok, "expected token pair to be found") | ||
|
||
//nolint:dupl | ||
testCases := []struct { | ||
name string | ||
postCheck func() | ||
}{ | ||
{ | ||
"success", | ||
func() { | ||
redeemLog := s.stateDB.Logs()[0] | ||
s.Require().Equal(redeemLog.Address, s.precompile.Address()) | ||
// Check event signature matches the one emitted | ||
event := s.precompile.ABI.Events[stride.EventTypeRedeem] | ||
s.Require().Equal(event.ID, common.HexToHash(redeemLog.Topics[0].Hex())) | ||
s.Require().Equal(redeemLog.BlockNumber, uint64(s.ctx.BlockHeight())) | ||
|
||
var redeemEvent stride.EventRedeem | ||
err := cmn.UnpackLog(s.precompile.ABI, &redeemEvent, stride.EventTypeRedeem, *redeemLog) | ||
s.Require().NoError(err) | ||
s.Require().Equal(common.BytesToAddress(s.address.Bytes()), redeemEvent.Sender) | ||
s.Require().Equal(common.HexToAddress(tokenPair.Erc20Address), redeemEvent.Token) | ||
s.Require().Equal(big.NewInt(1e18), redeemEvent.Amount) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
s.Run(tc.name, func() { | ||
s.SetupTest() | ||
|
||
err := s.precompile.EmitRedeemEvent(s.ctx, s.stateDB, s.address, common.HexToAddress(tokenPair.Erc20Address), receiver, big.NewInt(1e18)) | ||
s.Require().NoError(err) | ||
tc.postCheck() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.