-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ethereum light client (#3586)
* feat: add ethereum light client * rename to eth * Fix import --------- Co-authored-by: Eric Warehime <[email protected]>
- Loading branch information
1 parent
0eee1cd
commit 5aa09c9
Showing
4 changed files
with
95 additions
and
0 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
Binary file not shown.
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,59 @@ | ||
package v23_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
|
||
ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10/types" | ||
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types" | ||
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported" | ||
|
||
"github.com/cosmos/gaia/v23/app/helpers" | ||
v23 "github.com/cosmos/gaia/v23/app/upgrades/v23" | ||
) | ||
|
||
const ( | ||
clientStateJSON = `{"@type":"/ibc.lightclients.wasm.v1.ClientState","data":"eyJjaGFpbl9pZCI6MzE1MTkwOCwiZXBvY2hzX3Blcl9zeW5jX2NvbW1pdHRlZV9wZXJpb2QiOjgsImZvcmtfcGFyYW1ldGVycyI6eyJhbHRhaXIiOnsiZXBvY2giOjAsInZlcnNpb24iOiIyMDAwMDAzOCJ9LCJiZWxsYXRyaXgiOnsiZXBvY2giOjAsInZlcnNpb24iOiIzMDAwMDAzOCJ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lIjoiMHg4MTQ1ZjkyZDEzMTcxNTNlNmJiODFhOTAzZGI2ZjBiMTBjNTBhOTM2ODNmNGMyYWFiMzVlOWE4YTRiYjI4MzMyMzQyNWZiNTZhNDdkOGIzMGE5ZWZkNTA5YzhhZjE0ZTEiLCJzbG90IjozMiwic3RhdGVfcm9vdCI6IjB4MjI4NTQzYWVlYzk0NjA5YjQwOGUyNzI0NjIzZjgyMGExNjFhYmY5OWRkODMyNzQ4MWQ1NGNmYmUyNzAyOTE1ZCIsInN0b3JhZ2Vfcm9vdCI6IjB4MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMCIsInRpbWVzdGFtcCI6MTc0MDgyNzU5OX0="}` | ||
) | ||
|
||
func TestAddEthLightWasmLightClient(t *testing.T) { | ||
gaiaApp := helpers.Setup(t) | ||
ctx := gaiaApp.NewUncachedContext(true, tmproto.Header{ | ||
Time: time.Unix(1740829624, 0), | ||
}) | ||
|
||
err := v23.AddEthLightWasmLightClient(ctx, gaiaApp.WasmClientKeeper) | ||
require.NoError(t, err) | ||
|
||
// check that the checksum is as expected | ||
queryChecksumsResp, err := gaiaApp.WasmClientKeeper.Checksums(ctx, &ibcwasmtypes.QueryChecksumsRequest{}) | ||
require.NoError(t, err) | ||
require.Len(t, queryChecksumsResp.Checksums, 1) | ||
require.Equal(t, v23.ExpectedEthLightClientChecksum, queryChecksumsResp.Checksums[0]) | ||
|
||
var clientState ibcexported.ClientState | ||
err = gaiaApp.AppCodec().UnmarshalInterfaceJSON([]byte(clientStateJSON), &clientState) | ||
require.NoError(t, err) | ||
|
||
var consensusState ibcexported.ConsensusState | ||
err = gaiaApp.AppCodec().UnmarshalInterfaceJSON([]byte(consensusStateJSON), &consensusState) | ||
require.NoError(t, err) | ||
|
||
createMsg, err := clienttypes.NewMsgCreateClient(clientState, consensusState, "") | ||
require.NoError(t, err) | ||
|
||
// create a light client | ||
createClientResp, err := gaiaApp.IBCKeeper.CreateClient(ctx, createMsg) | ||
require.NoError(t, err) | ||
require.Equal(t, "08-wasm-0", createClientResp.ClientId) | ||
|
||
// Make a call into the actual light client to verify we can call the light client contract | ||
timestamp, err := gaiaApp.IBCKeeper.ClientKeeper.GetClientTimestampAtHeight(ctx, "08-wasm-0", clienttypes.NewHeight(0, 32)) | ||
require.NoError(t, err) | ||
require.Equal(t, uint64(1740827599000000000), timestamp) | ||
} |