|
| 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 | +} |
0 commit comments