diff --git a/proto/cosmos/oracle/v1/event.proto b/proto/cosmos/oracle/v1/event.proto index 080a17ba5c..ce40f03749 100644 --- a/proto/cosmos/oracle/v1/event.proto +++ b/proto/cosmos/oracle/v1/event.proto @@ -14,5 +14,5 @@ message EventPackageClaim { int64 send_sequence = 5; bool crash = 6; string error_msg = 7; - int64 fee = 8; + string relay_fee = 8; } \ No newline at end of file diff --git a/simapp/app.go b/simapp/app.go index d22d2cb405..d5433e107f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -144,6 +144,7 @@ var ( stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, nft.ModuleName: nil, + crosschaintypes.ModuleName: nil, } ) diff --git a/types/cross_chain.go b/types/cross_chain.go index 2cab476073..28a6312207 100644 --- a/types/cross_chain.go +++ b/types/cross_chain.go @@ -53,7 +53,7 @@ func ParseChainID(input string) (ChainID, error) { } type CrossChainApplication interface { - ExecuteSynPackage(ctx Context, payload []byte, relayerFee int64) ExecuteResult + ExecuteSynPackage(ctx Context, payload []byte, relayerFee *big.Int) ExecuteResult ExecuteAckPackage(ctx Context, payload []byte) ExecuteResult // When the ack application crash, payload is the payload of the origin package. ExecuteFailAckPackage(ctx Context, payload []byte) ExecuteResult @@ -89,7 +89,7 @@ func EncodePackageHeader(packageType CrossChainPackageType, timestamp uint64, re timestampBytes := make([]byte, TimestampLength) binary.BigEndian.PutUint64(timestampBytes, timestamp) - copy(packageHeader[CrossChainFeeLength:CrossChainFeeLength+TimestampLength], timestampBytes) + copy(packageHeader[PackageTypeLength:PackageTypeLength+TimestampLength], timestampBytes) length := len(relayerFee.Bytes()) copy(packageHeader[PackageHeaderLength-length:PackageHeaderLength], relayerFee.Bytes()) @@ -103,7 +103,7 @@ func DecodePackageHeader(packageHeader []byte) (packageType CrossChainPackageTyp } packageType = CrossChainPackageType(packageHeader[0]) - timestamp = binary.BigEndian.Uint64(packageHeader[PackageTypeLength : CrossChainFeeLength+TimestampLength]) + timestamp = binary.BigEndian.Uint64(packageHeader[PackageTypeLength : PackageTypeLength+TimestampLength]) relayFee.SetBytes(packageHeader[PackageTypeLength+TimestampLength : PackageHeaderLength]) return diff --git a/x/crosschain/testutil/mockapp.go b/x/crosschain/testutil/mockapp.go index 8ed4f3f396..0b09dc9adb 100644 --- a/x/crosschain/testutil/mockapp.go +++ b/x/crosschain/testutil/mockapp.go @@ -3,10 +3,12 @@ package testutil import ( + "math/big" reflect "reflect" - types "github.com/cosmos/cosmos-sdk/types" gomock "github.com/golang/mock/gomock" + + types "github.com/cosmos/cosmos-sdk/types" ) // MockCrossChainApplication is a mock of CrossChainApplication interface @@ -33,7 +35,7 @@ func (m *MockCrossChainApplication) EXPECT() *MockCrossChainApplicationMockRecor } // ExecuteSynPackage mocks base method -func (m *MockCrossChainApplication) ExecuteSynPackage(ctx types.Context, payload []byte, relayerFee int64) types.ExecuteResult { +func (m *MockCrossChainApplication) ExecuteSynPackage(ctx types.Context, payload []byte, relayerFee *big.Int) types.ExecuteResult { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExecuteSynPackage", ctx, payload, relayerFee) ret0, _ := ret[0].(types.ExecuteResult) diff --git a/x/oracle/keeper/keeper_test.go b/x/oracle/keeper/keeper_test.go index 8f1cc16cad..4a4816283b 100644 --- a/x/oracle/keeper/keeper_test.go +++ b/x/oracle/keeper/keeper_test.go @@ -13,6 +13,11 @@ import ( tmtime "github.com/tendermint/tendermint/types/time" "github.com/willf/bitset" + crosschaintypes "github.com/cosmos/cosmos-sdk/x/crosschain/types" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + + "github.com/cosmos/cosmos-sdk/x/oracle/keeper" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/simapp" @@ -28,6 +33,8 @@ type TestSuite struct { app *simapp.SimApp ctx sdk.Context + + msgServer types.MsgServer } func (s *TestSuite) SetupTest() { @@ -39,6 +46,16 @@ func (s *TestSuite) SetupTest() { s.app = app s.ctx = ctx + + s.app.CrossChainKeeper.SetSrcChainID(sdk.ChainID(1)) + + coins := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(100000))) + err := s.app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, coins) + s.NoError(err) + err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, crosschaintypes.ModuleName, coins) + s.NoError(err) + + s.msgServer = keeper.NewMsgServerImpl(s.app.OracleKeeper) } func TestTestSuite(t *testing.T) { diff --git a/x/oracle/keeper/msg_server.go b/x/oracle/keeper/msg_server.go index 0d0d520ac6..ee72097a3c 100644 --- a/x/oracle/keeper/msg_server.go +++ b/x/oracle/keeper/msg_server.go @@ -4,6 +4,7 @@ import ( "context" "encoding/hex" "fmt" + "math/big" "runtime/debug" sdkerrors "cosmossdk.io/errors" @@ -31,6 +32,8 @@ var _ types.MsgServer = msgServer{} func (k msgServer) Claim(goCtx context.Context, req *types.MsgClaim) (*types.MsgClaimResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + logger := k.oracleKeeper.Logger(ctx) + // check dest chain id if sdk.ChainID(req.DestChainId) != k.oracleKeeper.CrossChainKeeper.GetSrcChainID() { return nil, sdkerrors.Wrapf(types.ErrInvalidDestChainId, fmt.Sprintf("dest chain id(%d) should be %d", req.SrcChainId, k.oracleKeeper.CrossChainKeeper.GetSrcChainID())) @@ -57,10 +60,10 @@ func (k msgServer) Claim(goCtx context.Context, req *types.MsgClaim) (*types.Msg event, err := handlePackage(ctx, req, k.oracleKeeper, sdk.ChainID(req.SrcChainId), &pack) if err != nil { // only do log, but let reset package get chance to execute. - ctx.Logger().With("module", "oracle").Error(fmt.Sprintf("process package failed, channel=%d, sequence=%d, error=%v", pack.ChannelId, pack.Sequence, err)) + logger.Error(fmt.Sprintf("process package failed, channel=%d, sequence=%d, error=%v", pack.ChannelId, pack.Sequence, err)) return nil, err } - ctx.Logger().With("module", "oracle").Info(fmt.Sprintf("process package success, channel=%d, sequence=%d", pack.ChannelId, pack.Sequence)) + logger.Info(fmt.Sprintf("process package success, channel=%d, sequence=%d", pack.ChannelId, pack.Sequence)) events = append(events, event) @@ -74,7 +77,7 @@ func (k msgServer) Claim(goCtx context.Context, req *types.MsgClaim) (*types.Msg } func handlePackage(ctx sdk.Context, req *types.MsgClaim, oracleKeeper Keeper, chainId sdk.ChainID, pack *types.Package) (*types.EventPackageClaim, error) { - logger := ctx.Logger().With("module", "x/oracle") + logger := oracleKeeper.Logger(ctx) crossChainApp := oracleKeeper.CrossChainKeeper.GetCrossChainApp(pack.ChannelId) if crossChainApp == nil { @@ -92,26 +95,22 @@ func handlePackage(ctx sdk.Context, req *types.MsgClaim, oracleKeeper Keeper, ch } if timestamp != req.Timestamp { - return nil, sdkerrors.Wrapf(types.ErrInvalidPayloadHeader, "timestamp is not the same in payload header") + return nil, sdkerrors.Wrapf(types.ErrInvalidPayloadHeader, "timestamp(%d) is not the same in payload header(%d)", req.Timestamp, timestamp) } if !sdk.IsValidCrossChainPackageType(packageType) { return nil, sdkerrors.Wrapf(types.ErrInvalidPackageType, fmt.Sprintf("package type %d is invalid", packageType)) } - feeAmount := relayFee.Int64() - if feeAmount < 0 { - return nil, sdkerrors.Wrapf(types.ErrFeeOverflow, fmt.Sprintf("fee(%s) is overflow", relayFee.String())) - } - - fee := sdk.Coins{sdk.Coin{Denom: sdk.NativeTokenSymbol, Amount: sdk.NewInt(feeAmount)}} + bondDenom := oracleKeeper.StakingKeeper.BondDenom(ctx) + fee := sdk.Coins{sdk.Coin{Denom: bondDenom, Amount: sdk.NewIntFromBigInt(&relayFee)}} err = oracleKeeper.SendCoinsToFeeCollector(ctx, fee) if err != nil { return nil, err } cacheCtx, write := ctx.CacheContext() - crash, result := executeClaim(cacheCtx, crossChainApp, pack.Payload, packageType, feeAmount) + crash, result := executeClaim(cacheCtx, crossChainApp, pack.Payload, packageType, &relayFee) if result.IsOk() { write() } else { @@ -156,7 +155,7 @@ func handlePackage(ctx sdk.Context, req *types.MsgClaim, oracleKeeper Keeper, ch PackageType: uint32(packageType), ReceiveSequence: pack.Sequence, SendSequence: sendSequence, - Fee: feeAmount, + RelayFee: relayFee.String(), Crash: crash, ErrorMsg: result.ErrMsg(), } @@ -164,7 +163,7 @@ func handlePackage(ctx sdk.Context, req *types.MsgClaim, oracleKeeper Keeper, ch return claimEvent, nil } -func executeClaim(ctx sdk.Context, app sdk.CrossChainApplication, payload []byte, packageType sdk.CrossChainPackageType, relayerFee int64) (crash bool, result sdk.ExecuteResult) { +func executeClaim(ctx sdk.Context, app sdk.CrossChainApplication, payload []byte, packageType sdk.CrossChainPackageType, relayerFee *big.Int) (crash bool, result sdk.ExecuteResult) { defer func() { if r := recover(); r != nil { log := fmt.Sprintf("recovered: %v\nstack:\n%v", r, string(debug.Stack())) diff --git a/x/oracle/keeper/msg_server_test.go b/x/oracle/keeper/msg_server_test.go new file mode 100644 index 0000000000..e0fdddad0f --- /dev/null +++ b/x/oracle/keeper/msg_server_test.go @@ -0,0 +1,147 @@ +package keeper_test + +import ( + "math/big" + "time" + + "github.com/willf/bitset" + + "github.com/cosmos/cosmos-sdk/bsc/rlp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/oracle/testutil" + "github.com/cosmos/cosmos-sdk/x/oracle/types" +) + +type DummyCrossChainApp struct { +} + +func (ta *DummyCrossChainApp) ExecuteSynPackage(ctx sdk.Context, payload []byte, relayerFee *big.Int) sdk.ExecuteResult { + return sdk.ExecuteResult{} +} + +func (ta *DummyCrossChainApp) ExecuteAckPackage(ctx sdk.Context, payload []byte) sdk.ExecuteResult { + return sdk.ExecuteResult{} +} + +func (ta *DummyCrossChainApp) ExecuteFailAckPackage(ctx sdk.Context, payload []byte) sdk.ExecuteResult { + return sdk.ExecuteResult{} +} + +func (s *TestSuite) TestClaim() { + s.app.CrossChainKeeper.RegisterChannel("test", sdk.ChannelID(1), &DummyCrossChainApp{}) + + s.app.OracleKeeper.SetParams(s.ctx, types.Params{ + RelayerTimeout: 5, + RelayerBackoffTime: 3, + }) + + _, _, newValidators, blsKeys := createValidators(s.T(), s.ctx, s.app, []int64{9, 8, 7}) + + validators := s.app.StakingKeeper.GetLastValidators(s.ctx) + validatorMap := make(map[string]int, 0) + for idx, validator := range validators { + validatorMap[validator.RelayerAddress] = idx + } + + payloadHeader := sdk.EncodePackageHeader(sdk.SynCrossChainPackageType, 1992, *big.NewInt(1)) + + testPackage := types.Package{ + ChannelId: 1, + Sequence: 0, + Payload: append(payloadHeader, []byte("test payload")...), + } + + packageBytes, err := rlp.EncodeToBytes([]types.Package{testPackage}) + s.Require().Nil(err, "encode package error") + + msgClaim := types.MsgClaim{ + FromAddress: validators[0].RelayerAddress, + SrcChainId: 56, + DestChainId: 1, + Sequence: 0, + Timestamp: 1992, + Payload: packageBytes, + VoteAddressSet: []uint64{0, 1}, + AggSignature: []byte("test sig"), + } + + blsSignBytes := msgClaim.GetBlsSignBytes() + + valBitSet := bitset.New(256) + for _, newValidator := range newValidators { + valBitSet.Set(uint(validatorMap[newValidator.RelayerAddress])) + } + + blsSig := testutil.GenerateBlsSig(blsKeys, blsSignBytes[:]) + msgClaim.VoteAddressSet = valBitSet.Bytes() + msgClaim.AggSignature = blsSig + + s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp), 0)) + _, err = s.msgServer.Claim(s.ctx, &msgClaim) + s.Require().Nil(err, "process claim msg error") +} + +func (s *TestSuite) TestInvalidClaim() { + s.app.CrossChainKeeper.RegisterChannel("test", sdk.ChannelID(1), &DummyCrossChainApp{}) + + s.app.OracleKeeper.SetParams(s.ctx, types.Params{ + RelayerTimeout: 5, + RelayerBackoffTime: 3, + }) + + _, _, newValidators, blsKeys := createValidators(s.T(), s.ctx, s.app, []int64{9, 8, 7}) + + validators := s.app.StakingKeeper.GetLastValidators(s.ctx) + validatorMap := make(map[string]int, 0) + for idx, validator := range validators { + validatorMap[validator.RelayerAddress] = idx + } + + msgClaim := types.MsgClaim{ + FromAddress: validators[0].RelayerAddress, + SrcChainId: 56, + DestChainId: 1, + Sequence: 0, + Timestamp: 1992, + Payload: []byte("invalid payload"), + VoteAddressSet: []uint64{0, 1}, + AggSignature: []byte("test sig"), + } + + blsSignBytes := msgClaim.GetBlsSignBytes() + + valBitSet := bitset.New(256) + for _, newValidator := range newValidators { + valBitSet.Set(uint(validatorMap[newValidator.RelayerAddress])) + } + + blsSig := testutil.GenerateBlsSig(blsKeys, blsSignBytes[:]) + msgClaim.VoteAddressSet = valBitSet.Bytes() + msgClaim.AggSignature = blsSig + + s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp), 0)) + _, err := s.msgServer.Claim(s.ctx, &msgClaim) + s.Require().NotNil(err, "process claim should return error") + s.Require().Contains(err.Error(), "decode payload error") + + // invalid timestamp + payloadHeader := sdk.EncodePackageHeader(sdk.SynCrossChainPackageType, 1993, *big.NewInt(1)) + testPackage := types.Package{ + ChannelId: 1, + Sequence: 0, + Payload: append(payloadHeader, []byte("test payload")...), + } + + packageBytes, err := rlp.EncodeToBytes([]types.Package{testPackage}) + s.Require().Nil(err, "encode package error") + + msgClaim.Payload = packageBytes + blsSignBytes = msgClaim.GetBlsSignBytes() + blsSig = testutil.GenerateBlsSig(blsKeys, blsSignBytes[:]) + msgClaim.AggSignature = blsSig + + s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp), 0)) + _, err = s.msgServer.Claim(s.ctx, &msgClaim) + s.Require().NotNil(err, "process claim should return error") + s.Require().Contains(err.Error(), "is not the same in payload header") +} diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index 0efefc03d6..c296cee58c 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -31,7 +31,7 @@ type EventPackageClaim struct { SendSequence int64 `protobuf:"varint,5,opt,name=send_sequence,json=sendSequence,proto3" json:"send_sequence,omitempty"` Crash bool `protobuf:"varint,6,opt,name=crash,proto3" json:"crash,omitempty"` ErrorMsg string `protobuf:"bytes,7,opt,name=error_msg,json=errorMsg,proto3" json:"error_msg,omitempty"` - Fee int64 `protobuf:"varint,8,opt,name=fee,proto3" json:"fee,omitempty"` + RelayFee string `protobuf:"bytes,8,opt,name=relay_fee,json=relayFee,proto3" json:"relay_fee,omitempty"` } func (m *EventPackageClaim) Reset() { *m = EventPackageClaim{} } @@ -116,11 +116,11 @@ func (m *EventPackageClaim) GetErrorMsg() string { return "" } -func (m *EventPackageClaim) GetFee() int64 { +func (m *EventPackageClaim) GetRelayFee() string { if m != nil { - return m.Fee + return m.RelayFee } - return 0 + return "" } func init() { @@ -130,28 +130,28 @@ func init() { func init() { proto.RegisterFile("cosmos/oracle/v1/event.proto", fileDescriptor_3e254cedc4112fb0) } var fileDescriptor_3e254cedc4112fb0 = []byte{ - // 321 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x91, 0xbb, 0x4e, 0xc3, 0x30, - 0x14, 0x86, 0xeb, 0x5e, 0x53, 0xd3, 0x8a, 0x62, 0x31, 0xa4, 0x5c, 0xa2, 0x00, 0x4b, 0x10, 0x22, - 0x51, 0xc5, 0x1b, 0x80, 0x3a, 0x74, 0x40, 0x42, 0x81, 0x89, 0x25, 0x72, 0x9d, 0x43, 0x12, 0xb5, - 0x89, 0x83, 0x9d, 0x46, 0xf4, 0x01, 0xd8, 0x79, 0x2c, 0xc6, 0x8e, 0x8c, 0xa8, 0x7d, 0x11, 0x14, - 0xc7, 0xc0, 0x94, 0xfc, 0xdf, 0xf7, 0xfb, 0x48, 0x3e, 0xc6, 0x27, 0x8c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x9d, 0x7e, 0x6e, 0x2d, 0xb4, 0xd9, 0x5a, 0xe8, 0x7b, 0x6b, 0xa1, 0x8f, 0x9d, 0xd5, - 0xd8, 0xec, 0xac, 0xc6, 0xd7, 0xce, 0x6a, 0x3c, 0x5f, 0x45, 0x49, 0x11, 0xaf, 0xe6, 0x2e, 0xe3, - 0xa9, 0x5e, 0x9d, 0xfe, 0x5c, 0xcb, 0x70, 0xe1, 0xbd, 0xfd, 0x3e, 0x42, 0x75, 0x5b, 0x39, 0xef, - 0xaa, 0xad, 0xde, 0xfc, 0x04, 0x00, 0x00, 0xff, 0xff, 0x51, 0xea, 0x27, 0x3a, 0xa2, 0x01, 0x00, - 0x00, + // 326 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x91, 0xcd, 0x4e, 0xe3, 0x30, + 0x14, 0x85, 0xeb, 0xfe, 0xa6, 0x9e, 0x56, 0xd3, 0xb1, 0x66, 0x91, 0xce, 0x40, 0x14, 0x60, 0x13, + 0x84, 0x48, 0x54, 0xf1, 0x06, 0xa0, 0x22, 0x75, 0x81, 0x84, 0x02, 0x2b, 0x36, 0x91, 0xeb, 0x5c, + 0x92, 0xa8, 0x49, 0x1c, 0xec, 0x34, 0xa2, 0x6f, 0xd1, 0xc7, 0x62, 0xd9, 0x25, 0x4b, 0xd4, 0xbe, + 0x08, 0x8a, 0x63, 0x60, 0x65, 0x9d, 0xef, 0x3b, 0xb6, 0xe4, 0x7b, 0xf1, 0x11, 0xe3, 0x32, 0xe3, + 0xd2, 0xe3, 0x82, 0xb2, 0x14, 0xbc, 0x6a, 0xe6, 0x41, 0x05, 0x79, 0xe9, 0x16, 0x82, 0x97, 0x9c, + 0x4c, 0x1a, 0xeb, 0x36, 0xd6, 0xad, 0x66, 0xff, 0xa6, 0x0d, 0x09, 0x94, 0xf7, 0xb4, 0x56, 0xe1, + 0x74, 0xdb, 0xc6, 0x7f, 0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, 0x0c, 0x57, 0xde, 0xeb, 0xd7, + 0x3e, 0xea, 0x8f, 0xcb, 0x65, 0x5f, 0x0d, 0xf8, 0xea, 0x33, 0x00, 0x00, 0xff, 0xff, 0xb7, 0xa8, + 0xb1, 0xcb, 0xad, 0x01, 0x00, 0x00, } func (m *EventPackageClaim) Marshal() (dAtA []byte, err error) { @@ -174,10 +174,12 @@ func (m *EventPackageClaim) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Fee != 0 { - i = encodeVarintEvent(dAtA, i, uint64(m.Fee)) + if len(m.RelayFee) > 0 { + i -= len(m.RelayFee) + copy(dAtA[i:], m.RelayFee) + i = encodeVarintEvent(dAtA, i, uint64(len(m.RelayFee))) i-- - dAtA[i] = 0x40 + dAtA[i] = 0x42 } if len(m.ErrorMsg) > 0 { i -= len(m.ErrorMsg) @@ -263,8 +265,9 @@ func (m *EventPackageClaim) Size() (n int) { if l > 0 { n += 1 + l + sovEvent(uint64(l)) } - if m.Fee != 0 { - n += 1 + sovEvent(uint64(m.Fee)) + l = len(m.RelayFee) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) } return n } @@ -452,10 +455,10 @@ func (m *EventPackageClaim) Unmarshal(dAtA []byte) error { m.ErrorMsg = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Fee", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RelayFee", wireType) } - m.Fee = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvent @@ -465,11 +468,24 @@ func (m *EventPackageClaim) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Fee |= int64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RelayFee = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEvent(dAtA[iNdEx:]) diff --git a/x/oracle/types/expected_keepers.go b/x/oracle/types/expected_keepers.go index 883bf0933d..a048efa221 100644 --- a/x/oracle/types/expected_keepers.go +++ b/x/oracle/types/expected_keepers.go @@ -7,6 +7,7 @@ import ( type StakingKeeper interface { GetLastValidators(ctx sdk.Context) (validators []types.Validator) + BondDenom(ctx sdk.Context) (res string) } type CrossChainKeeper interface { diff --git a/x/oracle/types/msgs_test.go b/x/oracle/types/msgs_test.go index 1c1dcfd691..608bad92b6 100644 --- a/x/oracle/types/msgs_test.go +++ b/x/oracle/types/msgs_test.go @@ -1,4 +1,4 @@ -package types +package types_test import ( "bytes" @@ -13,19 +13,21 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/simapp" "github.com/cosmos/cosmos-sdk/testutil" + "github.com/cosmos/cosmos-sdk/x/oracle/types" ) func TestBlsClaim(t *testing.T) { - claim := &BlsClaim{ - ChainId: 1, - Sequence: 1, - Timestamp: 1000, - Payload: []byte("test payload"), + claim := &types.BlsClaim{ + SrcChainId: 1, + DestChainId: 2, + Sequence: 1, + Timestamp: 1000, + Payload: []byte("test payload"), } signBytes := claim.GetSignBytes() - require.Equal(t, "954d4fe4c768c275f14ef32929ab83e182a4de3c0aef38964efdf0bc8f76eaff", + require.Equal(t, "0a0b49ef40324d4c511d7a81e1edeeccaa10b768e55cece473b5cd99137f05f6", hex.EncodeToString(signBytes[:])) } @@ -35,14 +37,15 @@ func TestValidateBasic(t *testing.T) { require.NoError(t, err) tests := []struct { - claimMsg MsgClaim + claimMsg types.MsgClaim expectedPass bool errorMsg string }{ { - MsgClaim{ + types.MsgClaim{ FromAddress: "random string", - ChainId: 1, + SrcChainId: 1, + DestChainId: 2, Sequence: 1, Payload: []byte("test payload"), VoteAddressSet: []uint64{0, 1}, @@ -52,9 +55,10 @@ func TestValidateBasic(t *testing.T) { "invalid from address", }, { - MsgClaim{ + types.MsgClaim{ FromAddress: addr.String(), - ChainId: math.MaxUint16 + 1, + SrcChainId: math.MaxUint16 + 1, + DestChainId: 2, Sequence: 1, Payload: []byte("test payload"), VoteAddressSet: []uint64{0, 1}, @@ -64,9 +68,23 @@ func TestValidateBasic(t *testing.T) { "chain id should not be larger than", }, { - MsgClaim{ + types.MsgClaim{ FromAddress: addr.String(), - ChainId: 100, + SrcChainId: 1, + DestChainId: math.MaxUint16 + 1, + Sequence: 1, + Payload: []byte("test payload"), + VoteAddressSet: []uint64{0, 1}, + AggSignature: []byte("test sig"), + }, + false, + "chain id should not be larger than", + }, + { + types.MsgClaim{ + FromAddress: addr.String(), + SrcChainId: 1, + DestChainId: 2, Sequence: 1, Payload: []byte{}, VoteAddressSet: []uint64{0, 1}, @@ -76,49 +94,53 @@ func TestValidateBasic(t *testing.T) { "payload should not be empty", }, { - MsgClaim{ + types.MsgClaim{ FromAddress: addr.String(), - ChainId: 100, + SrcChainId: 1, + DestChainId: 2, Sequence: 1, Payload: []byte("test payload"), VoteAddressSet: []uint64{0, 1}, AggSignature: []byte("test sig"), }, false, - fmt.Sprintf("length of vote addresse set should be %d", ValidatorBitSetLength), + fmt.Sprintf("length of vote addresse set should be %d", types.ValidatorBitSetLength), }, { - MsgClaim{ + types.MsgClaim{ FromAddress: addr.String(), - ChainId: 100, + SrcChainId: 1, + DestChainId: 2, Sequence: 1, Payload: []byte("test payload"), VoteAddressSet: []uint64{0, 1, 2, 3}, AggSignature: []byte("test sig"), }, false, - fmt.Sprintf("length of signature should be %d", BLSSignatureLength), + fmt.Sprintf("length of signature should be %d", types.BLSSignatureLength), }, { - MsgClaim{ + types.MsgClaim{ FromAddress: addr.String(), - ChainId: 100, + SrcChainId: 1, + DestChainId: 2, Sequence: 1, Payload: []byte("test payload"), VoteAddressSet: []uint64{0, 1, 2, 3}, - AggSignature: bytes.Repeat([]byte{0}, BLSSignatureLength), + AggSignature: bytes.Repeat([]byte{0}, types.BLSSignatureLength), }, false, "timestamp should not be 0", }, { - MsgClaim{ + types.MsgClaim{ FromAddress: addr.String(), - ChainId: 100, + SrcChainId: 1, + DestChainId: 2, Sequence: 1, Payload: []byte("test payload"), VoteAddressSet: []uint64{0, 1, 2, 3}, - AggSignature: bytes.Repeat([]byte{0}, BLSSignatureLength), + AggSignature: bytes.Repeat([]byte{0}, types.BLSSignatureLength), Timestamp: uint64(time.Now().Unix()), }, true,