From d324bf475cb9897d13eaf5376e0d6b09fad6312c Mon Sep 17 00:00:00 2001 From: sampocs Date: Mon, 8 Jan 2024 21:02:07 -0600 Subject: [PATCH] added back in core ibc testing files --- legacy_ibc_testing/core/events.go | 48 +++++++++++++++++++++ legacy_ibc_testing/core/expected_keepers.go | 20 +++++++++ 2 files changed, 68 insertions(+) create mode 100644 legacy_ibc_testing/core/events.go create mode 100644 legacy_ibc_testing/core/expected_keepers.go diff --git a/legacy_ibc_testing/core/events.go b/legacy_ibc_testing/core/events.go new file mode 100644 index 0000000000..daabc92d54 --- /dev/null +++ b/legacy_ibc_testing/core/events.go @@ -0,0 +1,48 @@ +package core + +import ( + "strconv" + + abci "github.com/cometbft/cometbft/abci/types" + + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" +) + +/* +TODO: Remove after upgrading to ibc-go v5 +legacy_ibc_testing is temporarily copied into the interchain-security repository for the purpose of testing only. +The integration test suites rely on modifications to ibc-go's test framework that cannot be back-ported to the canonical version that ics will rely on. +These files will be deprecated once ICS is able to upgrade to ibc-go v5. +*/ + +// ReconstructPacketFromEvent recreates a packet from an appropriate provided event +func ReconstructPacketFromEvent(event abci.Event) (packet types.Packet, err error) { + attrMap := make(map[string][]byte) + for _, attr := range event.Attributes { + attrMap[string(attr.Key)] = []byte(attr.Value) + } + + sequence, err := strconv.Atoi(string(attrMap[string(types.AttributeKeySequence)])) + if err != nil { + return packet, err + } + timeoutTimestamp, err := strconv.Atoi(string(attrMap[string(types.AttributeKeyTimeoutTimestamp)])) + if err != nil { + return packet, err + } + timeoutHeight, err := clienttypes.ParseHeight(string(attrMap[string(types.AttributeKeyTimeoutHeight)])) + if err != nil { + return packet, err + } + return types.NewPacket( + attrMap[string(types.AttributeKeyData)], // data + uint64(sequence), + string(attrMap[string(types.AttributeKeySrcPort)]), // sourcePort, + string(attrMap[string(types.AttributeKeySrcChannel)]), // sourceChannel, + string(attrMap[string(types.AttributeKeyDstPort)]), // destinationPort, + string(attrMap[string(types.AttributeKeyDstChannel)]), // destinationChannel string, + timeoutHeight, + uint64(timeoutTimestamp), + ), nil +} diff --git a/legacy_ibc_testing/core/expected_keepers.go b/legacy_ibc_testing/core/expected_keepers.go new file mode 100644 index 0000000000..90a9d40f3c --- /dev/null +++ b/legacy_ibc_testing/core/expected_keepers.go @@ -0,0 +1,20 @@ +package core + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +/* +TODO: Remove after upgrading to ibc-go v5 +legacy_ibc_testing is temporarily copied into the interchain-security repository for the purpose of testing only. +The integration test suites rely on modifications to ibc-go's test framework that cannot be back-ported to the canonical version that ics will rely on. +These files will be deprecated once ICS is able to upgrade to ibc-go v5. +*/ + +type StakingKeeper interface { + GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool) + UnbondingTime(ctx sdk.Context) time.Duration +}