Skip to content

Commit

Permalink
fix(eibc): add test cases for authorized order fulfillment (#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Oct 24, 2024
1 parent c9dae97 commit ae279de
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions x/eibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
dacktypes "github.com/dymensionxyz/dymension/v3/x/delayedack/types"
"github.com/dymensionxyz/dymension/v3/x/eibc/types"
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)

func (suite *KeeperTestSuite) TestMsgFulfillOrder() {
Expand Down Expand Up @@ -157,6 +158,7 @@ func (suite *KeeperTestSuite) TestMsgFulfillOrderAuthorized() {
msg *types.MsgFulfillOrderAuthorized
lpAccountBalance sdk.Coins
operatorFeeAccountBalance sdk.Coins
malleate func()
expectError error
expectOrderFulfilled bool
expectedLPAccountBalance sdk.Coins
Expand All @@ -183,6 +185,42 @@ func (suite *KeeperTestSuite) TestMsgFulfillOrderAuthorized() {
expectedLPAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 108)), // 200 - 90 (price) - 2 (operator fee)
expectedOperatorFeeAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 52)), // 50 + 2 (operator fee)
},
{
name: "Successful fulfillment with settlement",
orderPrice: sdk.NewInt64Coin("adym", 90),
orderFee: sdk.NewInt(10),
orderRecipient: sample.AccAddress(),
msg: &types.MsgFulfillOrderAuthorized{
RollappId: rollappPacket.RollappId,
Price: sdk.NewCoins(sdk.NewInt64Coin("adym", 90)),
ExpectedFee: "10",
OperatorFeeShare: sdk.DecProto{Dec: sdk.NewDecWithPrec(2, 1)}, // 0.2
OperatorFeeAddress: sample.AccAddress(),
LpAddress: sample.AccAddress(),
SettlementValidated: true,
},
lpAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 200)),
operatorFeeAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 50)),
malleate: func() {
rollappPacket.ProofHeight = 1
siIndex := rollapptypes.StateInfoIndex{
RollappId: rollappPacket.RollappId,
Index: 1,
}
suite.App.RollappKeeper.SetLatestStateInfoIndex(suite.Ctx, siIndex)
suite.App.RollappKeeper.SetStateInfo(suite.Ctx, rollapptypes.StateInfo{
StateInfoIndex: siIndex,
StartHeight: 1,
NumBlocks: 1,
Status: commontypes.Status_PENDING,
})

},
expectError: nil,
expectOrderFulfilled: true,
expectedLPAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 108)), // 200 - 90 (price) - 2 (operator fee)
expectedOperatorFeeAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 52)), // 50 + 2 (operator fee)
},
{
name: "Failure due to mismatched rollapp ID",
orderPrice: sdk.NewInt64Coin("adym", 100),
Expand Down Expand Up @@ -302,13 +340,53 @@ func (suite *KeeperTestSuite) TestMsgFulfillOrderAuthorized() {
expectOrderFulfilled: false,
expectedLPAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 90)), // Unchanged
},
{
name: "Failure due to not settlement validated",
orderPrice: sdk.NewInt64Coin("adym", 100),
orderFee: sdk.NewInt(10),
orderRecipient: sample.AccAddress(),
msg: &types.MsgFulfillOrderAuthorized{
RollappId: rollappPacket.RollappId,
Price: sdk.NewCoins(sdk.NewInt64Coin("adym", 100)),
ExpectedFee: "10",
OperatorFeeShare: sdk.DecProto{Dec: sdk.NewDecWithPrec(2, 1)}, // 0.2
OperatorFeeAddress: sample.AccAddress(),
LpAddress: sample.AccAddress(),
SettlementValidated: true,
},
lpAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 200)),
operatorFeeAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 50)),
malleate: func() {
rollappPacket.ProofHeight = 10
siIndex := rollapptypes.StateInfoIndex{
RollappId: rollappPacket.RollappId,
Index: 1,
}
suite.App.RollappKeeper.SetLatestStateInfoIndex(suite.Ctx, siIndex)
suite.App.RollappKeeper.SetStateInfo(suite.Ctx, rollapptypes.StateInfo{
StateInfoIndex: siIndex,
StartHeight: 1,
NumBlocks: 1,
Status: commontypes.Status_PENDING,
})

},
expectError: types.ErrOrderNotSettlementValidated,
expectOrderFulfilled: false,
expectedLPAccountBalance: sdk.NewCoins(sdk.NewInt64Coin("adym", 200)), // Unchanged
},
}

for _, tc := range tests {
suite.Run(tc.name, func() {
// Set up initial state
suite.SetupTest() // Reset the context and keepers before each test

// Malleate the test state
if tc.malleate != nil {
tc.malleate()
}

// Create accounts
var lpAccount, operatorFeeAccount sdk.AccAddress

Expand Down

0 comments on commit ae279de

Please sign in to comment.