Skip to content

Commit 1f96379

Browse files
author
fankaiqiang
committed
add vote test case
1 parent 1c1b53a commit 1f96379

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/test/java/com/binance/dex/api/client/encoding/message/TransactionRequestAssemblerTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.binance.dex.api.client.domain.TimeInForce;
88
import com.binance.dex.api.client.domain.broadcast.*;
99
import com.binance.dex.api.client.encoding.EncodeUtils;
10+
import com.google.common.collect.Lists;
1011
import org.junit.Assert;
1112
import org.junit.Test;
1213

@@ -226,6 +227,43 @@ public void testTokenUnfreeze() throws IOException, NoSuchAlgorithmException {
226227
EncodeUtils.bytesToHex(assembler.encodeStdTx(encodedMsg, encodedSignature)));
227228
}
228229

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+
229267
@Test(expected=IllegalArgumentException.class)
230268
public void testOverFlow() {
231269
String n = "922337203685";

0 commit comments

Comments
 (0)