|
7 | 7 | import com.binance.dex.api.client.domain.TimeInForce; |
8 | 8 | import com.binance.dex.api.client.domain.broadcast.*; |
9 | 9 | import com.binance.dex.api.client.encoding.EncodeUtils; |
| 10 | +import com.google.common.collect.Lists; |
10 | 11 | import org.junit.Assert; |
11 | 12 | import org.junit.Test; |
12 | 13 |
|
@@ -226,6 +227,43 @@ public void testTokenUnfreeze() throws IOException, NoSuchAlgorithmException { |
226 | 227 | EncodeUtils.bytesToHex(assembler.encodeStdTx(encodedMsg, encodedSignature))); |
227 | 228 | } |
228 | 229 |
|
| 230 | + @Test |
| 231 | + public void testVote() throws IOException, NoSuchAlgorithmException { |
| 232 | + List<String> words = Arrays.asList("trial raw kiss bench silent crystal clever cloud chapter obvious error income mechanic attend army outer found cube tribe sort south possible scene fox".split(" ")); |
| 233 | + Wallet wallet = Wallet.createWalletFromMnemonicCode(words, BinanceDexEnvironment.TEST_NET); |
| 234 | + |
| 235 | + Assert.assertEquals("tbnb1mrslq6lhglm3jp7pxzlk8u4549pmtp9sgvn2rc", wallet.getAddress()); |
| 236 | + wallet.setAccountNumber(0); |
| 237 | + wallet.setSequence(9L); |
| 238 | + wallet.setChainId("test-chain-n4b735"); |
| 239 | + |
| 240 | + TransactionOption options = new TransactionOption("", 0, null); |
| 241 | + TransactionRequestAssembler assembler = new TransactionRequestAssembler(wallet, options); |
| 242 | + |
| 243 | + Vote vote = new Vote(); |
| 244 | + vote.setProposalId(347L); |
| 245 | + vote.setOption(1); |
| 246 | + |
| 247 | + VoteMessage voteMessage = assembler.createVoteMessage(vote); |
| 248 | + byte[] encodedMsg = assembler.encodeVoteMessage(voteMessage); |
| 249 | + |
| 250 | + Assert.assertEquals("a1cadd3608db021214d8e1f06bf747f71907c130bf63f2b4a943b584b01801", |
| 251 | + EncodeUtils.bytesToHex(encodedMsg)); |
| 252 | + |
| 253 | + byte[] signature = assembler.sign(voteMessage); |
| 254 | + Assert.assertEquals( |
| 255 | + "37f4f39cf414461c478f166a2d59705dd8566fd573214c5c002a075d6a6d86c237d6f237c35983d001e4b322b1d0f9cef9328d670f163600e3af2226792c4b16".toLowerCase(), |
| 256 | + EncodeUtils.bytesToHex(signature)); |
| 257 | + |
| 258 | + byte[] encodedSignature = assembler.encodeSignature(signature); |
| 259 | + Assert.assertEquals( |
| 260 | + "0a26eb5ae987210280ec8943329305e43b2e6112728423ef9f9a7e7125621c3545c2f30ce08bf83c124037f4f39cf414461c478f166a2d59705dd8566fd573214c5c002a075d6a6d86c237d6f237c35983d001e4b322b1d0f9cef9328d670f163600e3af2226792c4b162009", |
| 261 | + EncodeUtils.bytesToHex(encodedSignature)); |
| 262 | + Assert.assertEquals( |
| 263 | + "9301f0625dee0a1fa1cadd3608db021214d8e1f06bf747f71907c130bf63f2b4a943b584b01801126c0a26eb5ae987210280ec8943329305e43b2e6112728423ef9f9a7e7125621c3545c2f30ce08bf83c124037f4f39cf414461c478f166a2d59705dd8566fd573214c5c002a075d6a6d86c237d6f237c35983d001e4b322b1d0f9cef9328d670f163600e3af2226792c4b162009", |
| 264 | + EncodeUtils.bytesToHex(assembler.encodeStdTx(encodedMsg, encodedSignature))); |
| 265 | + } |
| 266 | + |
229 | 267 | @Test(expected=IllegalArgumentException.class) |
230 | 268 | public void testOverFlow() { |
231 | 269 | String n = "922337203685"; |
|
0 commit comments