Skip to content

Commit 8a21358

Browse files
committed
test: add wasm light client test
1 parent 8bd6db4 commit 8a21358

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

tests/e2e/data/wasm_dummy_light_client.go

+3
Large diffs are not rendered by default.

tests/e2e/e2e_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var (
1717
runRateLimitTest = true
1818
runTxExtensionsTest = true
1919
runCWTest = true
20+
runWasmLightClientTest = true
2021
)
2122

2223
func (s *IntegrationTestSuite) TestRestInterfaces() {
@@ -139,3 +140,11 @@ func (s *IntegrationTestSuite) TestCW() {
139140
}
140141
s.testCWCounter()
141142
}
143+
144+
func (s *IntegrationTestSuite) TestWasmLightClient() {
145+
if !runWasmLightClientTest {
146+
s.T().Skip()
147+
}
148+
s.testStoreWasmLightClient()
149+
s.testCreateWasmLightClient()
150+
}
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package e2e
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"path/filepath"
7+
"strconv"
8+
"time"
9+
10+
"github.com/cosmos/gaia/v23/tests/e2e/data"
11+
)
12+
13+
const (
14+
proposalStoreWasmLightClientFilename = "proposal_store_wasm_light_client.json"
15+
wasmLightClientStateFilename = "wasm_light_client_state.json"
16+
wasmLightClientConsensusStateFilename = "wasm_light_client_consensus_state.json"
17+
)
18+
19+
func (s *IntegrationTestSuite) testStoreWasmLightClient() {
20+
chainEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))
21+
22+
validatorA := s.chainA.validators[0]
23+
validatorAAddr, _ := validatorA.keyInfo.GetAddress()
24+
25+
s.writeStoreWasmLightClientProposal(s.chainA)
26+
proposalCounter++
27+
submitGovFlags := []string{configFile(proposalStoreWasmLightClientFilename)}
28+
depositGovFlags := []string{strconv.Itoa(proposalCounter), depositAmount.String()}
29+
voteGovFlags := []string{strconv.Itoa(proposalCounter), "yes"}
30+
31+
s.T().Logf("Proposal number: %d", proposalCounter)
32+
s.T().Logf("Submitting, deposit and vote Gov Proposal: Store wasm light client code")
33+
s.submitGovProposal(chainEndpoint, validatorAAddr.String(), proposalCounter, "ibc.lightclients.wasm.v1.MsgStoreCode", submitGovFlags, depositGovFlags, voteGovFlags, "vote")
34+
35+
s.Require().Eventually(
36+
func() bool {
37+
s.T().Logf("After StoreWasmLightClient proposal")
38+
39+
res, err := queryIbcWasmChecksums(chainEndpoint)
40+
s.Require().NoError(err)
41+
s.Require().NotNil(res)
42+
s.Require().Equal(len(res), 1)
43+
44+
return true
45+
},
46+
15*time.Second,
47+
5*time.Second,
48+
)
49+
}
50+
51+
func (s *IntegrationTestSuite) testCreateWasmLightClient() {
52+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
53+
defer cancel()
54+
55+
s.writeClientAndConsensusState(s.chainA)
56+
57+
cmd := []string{
58+
gaiadBinary,
59+
txCommand,
60+
"ibc",
61+
"client",
62+
"create",
63+
wasmLightClientStateFilename,
64+
wasmLightClientConsensusStateFilename,
65+
}
66+
67+
s.T().Logf("Creating wasm light client on chain %s", s.chainA.id)
68+
s.executeGaiaTxCommand(ctx, s.chainA, cmd, 0, s.defaultExecValidation(s.chainA, 0))
69+
s.T().Log("successfully created wasm light client")
70+
}
71+
72+
func (s *IntegrationTestSuite) writeStoreWasmLightClientProposal(c *chain) {
73+
template := `
74+
{
75+
"messages": [
76+
{
77+
"@type": "/ibc.lightclients.wasm.v1.MsgStoreCode",
78+
"signer": "%s",
79+
"wasm_byte_code": "%s"
80+
}
81+
],
82+
"metadata": "AQ==",
83+
"deposit": "100uatom",
84+
"title": "Store wasm light client code",
85+
"summary": "e2e-test storing wasm light client code"
86+
}`
87+
propMsgBody := fmt.Sprintf(template,
88+
govAuthority,
89+
data.WasmDummyLightClient,
90+
)
91+
92+
err := writeFile(filepath.Join(c.validators[0].configDir(), "config", proposalStoreWasmLightClientFilename), []byte(propMsgBody))
93+
s.Require().NoError(err)
94+
}
95+
96+
func (s *IntegrationTestSuite) writeClientAndConsensusState(c *chain) {
97+
clientState := `{"@type":"/ibc.lightclients.wasm.v1.ClientState","data":"ZG9lc250IG1hdHRlcg==","checksum":"O45STPnbLLar4DtFwDx0dE6tuXQW5XTKPHpbjaugun4=","latest_height":{"revision_number":"0","revision_height":"7795583"}}`
98+
consensusState := `{"@type":"/ibc.lightclients.wasm.v1.ConsensusState","data":"ZG9lc250IG1hdHRlcg=="}`
99+
100+
err := writeFile(filepath.Join(c.validators[0].configDir(), "config", wasmLightClientStateFilename), []byte(clientState))
101+
s.Require().NoError(err)
102+
103+
err = writeFile(filepath.Join(c.validators[0].configDir(), "config", wasmLightClientConsensusStateFilename), []byte(consensusState))
104+
s.Require().NoError(err)
105+
}

tests/e2e/query.go

+15
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
ratelimittypes "github.com/cosmos/ibc-apps/modules/rate-limiting/v10/types"
11+
wasmclienttypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
1112
icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types"
1213
providertypes "github.com/cosmos/interchain-security/v7/x/ccv/provider/types"
1314

@@ -403,3 +404,17 @@ func queryWasmSmartContractState(endpoint, address, msg string) ([]byte, error)
403404

404405
return response.Data, nil
405406
}
407+
408+
func queryIbcWasmChecksums(endpoint string) ([]string, error) {
409+
body, err := httpGet(fmt.Sprintf("%s/ibc/lightclients/wasm/v1/checksums", endpoint))
410+
if err != nil {
411+
return nil, fmt.Errorf("failed to execute HTTP request: %w", err)
412+
}
413+
414+
var response wasmclienttypes.QueryChecksumsResponse
415+
if err = cdc.UnmarshalJSON(body, &response); err != nil {
416+
return nil, err
417+
}
418+
419+
return response.Checksums, nil
420+
}

0 commit comments

Comments
 (0)