|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "crypto/sha256" |
| 6 | + "fmt" |
| 7 | + "os" |
| 8 | + "path/filepath" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/stretchr/testify/assert/yaml" |
| 12 | + "github.com/stretchr/testify/require" |
| 13 | +) |
| 14 | + |
| 15 | +const ( |
| 16 | + Sha256SkipEntryPoint = "4ee07a1474cb1429cfbdba98fb52ca2efc2fe8602f8e1978dbc3f45b71511ca9" |
| 17 | + Sha256SkipAdapterIBCCallbacks = "21c375f75e09197478cd345b0a6376824a75471d8e22577dc36b74739277f027" |
| 18 | + SaltHex = "74657374696e67" // "testing" hex encoded |
| 19 | + RecipientAddress = "cosmos1hrgj37s5dcqrte6srj9p2uqul3nxpmmqfhqp67" |
| 20 | +) |
| 21 | + |
| 22 | +func (s *IntegrationTestSuite) testCallbacksCWSkipGo() { |
| 23 | + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) |
| 24 | + defer cancel() |
| 25 | + chainEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp")) |
| 26 | + |
| 27 | + valIdx := 0 |
| 28 | + val := s.chainA.validators[valIdx] |
| 29 | + address, _ := val.keyInfo.GetAddress() |
| 30 | + sender := address.String() |
| 31 | + dirName, err := os.Getwd() |
| 32 | + s.Require().NoError(err) |
| 33 | + |
| 34 | + // Copy file to container path and store the contract |
| 35 | + entryPointSrc := filepath.Join(dirName, "data/skip_go_entry_point.wasm") |
| 36 | + entryPointDst := filepath.Join(val.configDir(), "config", "skip_go_entry_point.wasm") |
| 37 | + _, err = copyFile(entryPointSrc, entryPointDst) |
| 38 | + s.Require().NoError(err) |
| 39 | + storeWasmPath := configFile("skip_go_entry_point.wasm") |
| 40 | + s.storeWasm(ctx, s.chainA, valIdx, sender, storeWasmPath) |
| 41 | + |
| 42 | + adapterSrc := filepath.Join(dirName, "data/skip_go_ibc_adapter_ibc_callbacks.wasm") |
| 43 | + adapterDst := filepath.Join(val.configDir(), "config", "skip_go_ibc_adapter_ibc_callbacks.wasm") |
| 44 | + _, err = copyFile(adapterSrc, adapterDst) |
| 45 | + s.Require().NoError(err) |
| 46 | + storeWasmPath = configFile("skip_go_ibc_adapter_ibc_callbacks.wasm") |
| 47 | + s.storeWasm(ctx, s.chainA, valIdx, sender, storeWasmPath) |
| 48 | + |
| 49 | + entrypointPredictedAddress := s.queryBuildAddress(ctx, s.chainA, valIdx, Sha256SkipEntryPoint, sender, SaltHex) |
| 50 | + s.Require().NoError(err) |
| 51 | + |
| 52 | + instantiateAdapterJSON := fmt.Sprintf(`{"entry_point_contract_address":"%s"}`, entrypointPredictedAddress) |
| 53 | + s.instantiateWasm(ctx, s.chainA, valIdx, sender, "3", instantiateAdapterJSON, "adapter") |
| 54 | + adapterAddress, err := queryWasmContractAddress(chainEndpoint, address.String(), 1) |
| 55 | + s.Require().NoError(err) |
| 56 | + |
| 57 | + instantiateEntrypointJSON := fmt.Sprintf(`{"swap_venues":[], "ibc_transfer_contract_address": "%s"}`, adapterAddress) |
| 58 | + s.instantiate2Wasm(ctx, s.chainA, valIdx, sender, "2", instantiateEntrypointJSON, SaltHex, "entrypoint") |
| 59 | + entrypointAddress, err := queryWasmContractAddress(chainEndpoint, address.String(), 2) |
| 60 | + s.Require().Equal(entrypointPredictedAddress, entrypointAddress) |
| 61 | + s.Require().NoError(err) |
| 62 | + |
| 63 | + s.T().Logf("Successfully deployed contracts: \nEntrypoint: %s\nAdapter:%s\n", entrypointAddress, adapterAddress) |
| 64 | + |
| 65 | + str := "transfer/channel-0/uatom" |
| 66 | + h := sha256.New() |
| 67 | + h.Write([]byte(str)) |
| 68 | + bs := h.Sum(nil) |
| 69 | + |
| 70 | + recipientDenom := fmt.Sprintf("ibc/%X", bs) |
| 71 | + |
| 72 | + ibcHooksData := fmt.Sprintf(`"wasm": { |
| 73 | + "contract": "%s", |
| 74 | + "msg": { |
| 75 | + "action": { |
| 76 | + "sent_asset": { |
| 77 | + "native": { |
| 78 | + "denom":"%s", |
| 79 | + "amount":"1" |
| 80 | + } |
| 81 | + }, |
| 82 | + "exact_out": false, |
| 83 | + "timeout_timestamp": %d, |
| 84 | + "action": { |
| 85 | + "transfer":{ |
| 86 | + "to_address": "%s" |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + }`, entrypointAddress, recipientDenom, time.Now().Add(time.Minute).UnixNano(), RecipientAddress) |
| 92 | + destCallbackData := fmt.Sprintf(`"dest_callback": { |
| 93 | + "address": "%s", |
| 94 | + "gas_limit": "%d" |
| 95 | + }`, adapterAddress, 10_000_000) |
| 96 | + |
| 97 | + memo := fmt.Sprintf("{%s,%s}", destCallbackData, ibcHooksData) |
| 98 | + |
| 99 | + senderB, _ := s.chainB.validators[0].keyInfo.GetAddress() |
| 100 | + s.sendIBC(s.chainB, 0, senderB.String(), adapterAddress, "1uatom", "3000000uatom", memo, transferChannel, nil, false) |
| 101 | + s.hermesClearPacket(hermesConfigWithGasPrices, s.chainB.id, transferPort, transferChannel) |
| 102 | + |
| 103 | + balances, err := queryGaiaAllBalances(chainEndpoint, RecipientAddress) |
| 104 | + if err != nil { |
| 105 | + return |
| 106 | + } |
| 107 | + |
| 108 | + require.Equal(s.T(), balances[0].String(), "1"+recipientDenom) |
| 109 | +} |
| 110 | + |
| 111 | +func (s *IntegrationTestSuite) queryBuildAddress(ctx context.Context, c *chain, valIdx int, codeHash, creatorAddress, saltHexEncoded string, |
| 112 | +) (res string) { |
| 113 | + cmd := []string{ |
| 114 | + gaiadBinary, |
| 115 | + queryCommand, |
| 116 | + "wasm", |
| 117 | + "build-address", |
| 118 | + codeHash, |
| 119 | + creatorAddress, |
| 120 | + saltHexEncoded, |
| 121 | + } |
| 122 | + |
| 123 | + s.executeGaiaTxCommand(ctx, c, cmd, valIdx, func(stdOut []byte, stdErr []byte) bool { |
| 124 | + s.Require().NoError(yaml.Unmarshal(stdOut, &res)) |
| 125 | + return true |
| 126 | + }) |
| 127 | + return res |
| 128 | +} |
0 commit comments