|
1 | 1 | package cosmos_test
|
2 |
| - |
3 |
| -// import ( |
4 |
| -// "encoding/hex" |
5 |
| -// "os" |
6 |
| -// "strings" |
7 |
| -// "time" |
8 |
| - |
9 |
| -// "github.com/tendermint/tendermint/crypto/secp256k1" |
10 |
| - |
11 |
| -// sdk "github.com/cosmos/cosmos-sdk/types" |
12 |
| -// "github.com/terra-project/core/app" |
13 |
| - |
14 |
| -// "github.com/renproject/multichain/chain/cosmos" |
15 |
| -// "github.com/renproject/multichain/compat/cosmoscompat" |
16 |
| -// "github.com/renproject/pack" |
17 |
| - |
18 |
| -// . "github.com/onsi/ginkgo" |
19 |
| -// . "github.com/onsi/gomega" |
20 |
| -// ) |
21 |
| - |
22 |
| -// var _ = Describe("Cosmos", func() { |
23 |
| -// Context("when submitting transactions", func() { |
24 |
| -// Context("when sending LUNA to multiple addresses", func() { |
25 |
| -// It("should work", func() { |
26 |
| -// // Load private key, and assume that the associated address has |
27 |
| -// // funds to spend. You can do this by setting TERRA_PK to the |
28 |
| -// // value specified in the `./multichaindeploy/.env` file. |
29 |
| -// pkEnv := os.Getenv("TERRA_PK") |
30 |
| -// if pkEnv == "" { |
31 |
| -// panic("TERRA_PK is undefined") |
32 |
| -// } |
33 |
| - |
34 |
| -// addrEnv := os.Getenv("TERRA_ADDRESS") |
35 |
| -// if addrEnv == "" { |
36 |
| -// panic("TERRA_ADDRESS is undefined") |
37 |
| -// } |
38 |
| - |
39 |
| -// // pkEnv := "a96e62ed3955e65be32703f12d87b6b5cf26039ecfa948dc5107a495418e5330" |
40 |
| -// // addrEnv := "terra10s4mg25tu6termrk8egltfyme4q7sg3hl8s38u" |
41 |
| - |
42 |
| -// pkBz, err := hex.DecodeString(pkEnv) |
43 |
| -// Expect(err).ToNot(HaveOccurred()) |
44 |
| - |
45 |
| -// var pk secp256k1.PrivKeySecp256k1 |
46 |
| -// copy(pk[:], pkBz) |
47 |
| - |
48 |
| -// addr := cosmoscompat.Address(pk.PubKey().Address()) |
49 |
| - |
50 |
| -// decoder := cosmos.NewAddressDecoder("terra") |
51 |
| -// expectedAddr, err := decoder.DecodeAddress(pack.NewString(addrEnv)) |
52 |
| -// Expect(err).ToNot(HaveOccurred()) |
53 |
| -// Expect(addr).Should(Equal(expectedAddr)) |
54 |
| - |
55 |
| -// pk1 := secp256k1.GenPrivKey() |
56 |
| -// pk2 := secp256k1.GenPrivKey() |
57 |
| - |
58 |
| -// recipient1 := sdk.AccAddress(pk1.PubKey().Address()) |
59 |
| -// recipient2 := sdk.AccAddress(pk2.PubKey().Address()) |
60 |
| - |
61 |
| -// msgs := []cosmoscompat.MsgSend{ |
62 |
| -// { |
63 |
| -// FromAddress: cosmoscompat.Address(addr), |
64 |
| -// ToAddress: cosmoscompat.Address(recipient1), |
65 |
| -// Amount: cosmoscompat.Coins{ |
66 |
| -// { |
67 |
| -// Denom: "uluna", |
68 |
| -// Amount: pack.U64(1000000), |
69 |
| -// }, |
70 |
| -// }, |
71 |
| -// }, |
72 |
| -// { |
73 |
| -// FromAddress: cosmoscompat.Address(addr), |
74 |
| -// ToAddress: cosmoscompat.Address(recipient2), |
75 |
| -// Amount: cosmoscompat.Coins{ |
76 |
| -// { |
77 |
| -// Denom: "uluna", |
78 |
| -// Amount: pack.U64(2000000), |
79 |
| -// }, |
80 |
| -// }, |
81 |
| -// }, |
82 |
| -// } |
83 |
| - |
84 |
| -// client := cosmoscompat.NewClient(cosmoscompat.DefaultClientOptions(), app.MakeCodec()) |
85 |
| -// account, err := client.Account(addr) |
86 |
| -// Expect(err).NotTo(HaveOccurred()) |
87 |
| - |
88 |
| -// txBuilder := cosmos.NewTxBuilder(cosmoscompat.TxOptions{ |
89 |
| -// AccountNumber: account.AccountNumber, |
90 |
| -// SequenceNumber: account.SequenceNumber, |
91 |
| -// Gas: 200000, |
92 |
| -// ChainID: "testnet", |
93 |
| -// Memo: "multichain", |
94 |
| -// Fees: cosmoscompat.Coins{ |
95 |
| -// { |
96 |
| -// Denom: "uluna", |
97 |
| -// Amount: pack.U64(3000), |
98 |
| -// }, |
99 |
| -// }, |
100 |
| -// }).WithCodec(app.MakeCodec()) |
101 |
| - |
102 |
| -// tx, err := txBuilder.BuildTx(msgs) |
103 |
| -// Expect(err).NotTo(HaveOccurred()) |
104 |
| - |
105 |
| -// sigBytes, err := pk.Sign(tx.SigBytes()) |
106 |
| -// Expect(err).NotTo(HaveOccurred()) |
107 |
| - |
108 |
| -// pubKey := pk.PubKey().(secp256k1.PubKeySecp256k1) |
109 |
| -// err = tx.Sign([]cosmoscompat.StdSignature{ |
110 |
| -// { |
111 |
| -// Signature: pack.NewBytes(sigBytes), |
112 |
| -// PubKey: pack.NewBytes(pubKey[:]), |
113 |
| -// }, |
114 |
| -// }) |
115 |
| -// Expect(err).NotTo(HaveOccurred()) |
116 |
| - |
117 |
| -// txHash, err := client.SubmitTx(tx, pack.NewString("sync")) |
118 |
| -// Expect(err).NotTo(HaveOccurred()) |
119 |
| - |
120 |
| -// for { |
121 |
| -// // Loop until the transaction has at least a few |
122 |
| -// // confirmations. This implies that the transaction is |
123 |
| -// // definitely valid, and the test has passed. We were |
124 |
| -// // successfully able to use the multichain to construct and |
125 |
| -// // submit a Bitcoin transaction! |
126 |
| -// _, err := client.Tx(txHash) |
127 |
| -// if err == nil { |
128 |
| -// break |
129 |
| -// } |
130 |
| - |
131 |
| -// if !strings.Contains(err.Error(), "not found") { |
132 |
| -// Expect(err).NotTo(HaveOccurred()) |
133 |
| -// } |
134 |
| - |
135 |
| -// time.Sleep(10 * time.Second) |
136 |
| -// } |
137 |
| -// }) |
138 |
| -// }) |
139 |
| -// }) |
140 |
| -// }) |
0 commit comments