Skip to content

Commit

Permalink
add getLiteServerVersion() and getRawTransactionsV2() methods to Tonlib;
Browse files Browse the repository at this point in the history
fix #86
  • Loading branch information
neodix42 committed Nov 28, 2024
1 parent b81759b commit dc588e0
Show file tree
Hide file tree
Showing 19 changed files with 833 additions and 312 deletions.
239 changes: 123 additions & 116 deletions address/src/test/java/org/ton/java/address/TestAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,121 +14,128 @@
@RunWith(JUnit4.class)
public class TestAddress {

public static final String TEST_ADDRESS_0 = "0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO";
public static final String TEST_ADDRESS_1 = "kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL";
public static final String TEST_ADDRESS_3 = "0:2cf55953e92efbeadab7ba725c3f93a0b23f842cbba72d7b8e6f510a70e422e3";
public static final String TEST_ADDRESS_4 = "kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYIny";

public static final String TEST_ADDRESS_5 = "-1:cdff07eb154c2e595930a6a9a4451608251cc1c894686c4c110894de43c96ad3";


@Test
public void testAddress() {

Address address03 = Address.of(TEST_ADDRESS_3);
assertThat(address03.toRaw()).isEqualTo(TEST_ADDRESS_3);

Address address04 = Address.of(TEST_ADDRESS_0);
assertThat(address04.toString(true, true, false)).isEqualTo("0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO");
assertThat(address04.isBounceable).isFalse();

Address address05 = Address.of(TEST_ADDRESS_0);
assertThat(address05.toString(true, true, true)).isEqualTo(TEST_ADDRESS_1);
assertThat(address05.isBounceable).isFalse();

Address address06 = Address.of(TEST_ADDRESS_0);
assertThat(address06.toString(false)).isEqualTo(TEST_ADDRESS_3);
assertThat(address06.isBounceable).isFalse();

Address address07 = Address.of(TEST_ADDRESS_1);
assertThat(address07.toString(true, true, false)).isEqualTo("0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO");
assertThat(address07.isBounceable).isTrue();

Address address08 = Address.of(TEST_ADDRESS_1);
assertThat(address08.toString(true, true, true)).isEqualTo(TEST_ADDRESS_1);
assertThat(address08.isBounceable).isTrue();

Address address09 = Address.of(TEST_ADDRESS_1);
assertThat(address09.toString(false)).isEqualTo(TEST_ADDRESS_3);
assertThat(address09.isBounceable).isTrue();

Address address10 = Address.of(TEST_ADDRESS_3);
assertThat(address10.toString(true, true, false, true)).isEqualTo("0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO");

Address address11 = Address.of(TEST_ADDRESS_3);
assertThat(address11.toString(true, true, true, true)).isEqualTo(TEST_ADDRESS_1);

Address address12 = Address.of(TEST_ADDRESS_3);
assertThat(address12.toString(false)).isEqualTo(TEST_ADDRESS_3);

Address address13 = Address.of("-1:3333333333333333333333333333333333333333333333333333333333333333");
assertThat(address13.toString(true, false, true, false)).isEqualTo("Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF");
assertThat(address13.toString(true, false, false, false)).isEqualTo("Uf8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMxYA");
assertThat(Utils.bytesToHex(address13.hashPart)).isEqualTo("3333333333333333333333333333333333333333333333333333333333333333");
assertThat(address13.hashPart.length).isEqualTo(32);
assertThat(address13.wc).isEqualTo((byte) -1);

Address address14 = Address.of(TEST_ADDRESS_4);
assertThat(address14.isTestOnly).isTrue();

assertThat(Address.isValid(TEST_ADDRESS_0)).isTrue();
assertThat(Address.isValid(TEST_ADDRESS_1)).isTrue();
assertThat(Address.isValid(TEST_ADDRESS_3)).isTrue();
assertThat(Address.isValid(TEST_ADDRESS_4)).isTrue();
assertThat(Address.isValid("bad_address")).isFalse();
}

@Test
public void testBadAddress() {
assertThrows(Error.class, () -> {
Address.of("");
Address.of("bad_input");
Address.of("kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYInz");
Address.of("ov_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYMg3");
Address.of("0:8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15:KsQHFLbKSMiYMg3");
public static final String TEST_ADDRESS_0 = "0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO";
public static final String TEST_ADDRESS_1 = "kQAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi47nL";
public static final String TEST_ADDRESS_3 =
"0:2cf55953e92efbeadab7ba725c3f93a0b23f842cbba72d7b8e6f510a70e422e3";
public static final String TEST_ADDRESS_4 = "kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYIny";

public static final String TEST_ADDRESS_5 =
"-1:cdff07eb154c2e595930a6a9a4451608251cc1c894686c4c110894de43c96ad3";

@Test
public void testAddress() {

Address address03 = Address.of(TEST_ADDRESS_3);
assertThat(address03.toRaw()).isEqualTo(TEST_ADDRESS_3);

Address address04 = Address.of(TEST_ADDRESS_0);
assertThat(address04.toString(true, true, false))
.isEqualTo("0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO");
assertThat(address04.isBounceable).isFalse();

Address address05 = Address.of(TEST_ADDRESS_0);
assertThat(address05.toString(true, true, true)).isEqualTo(TEST_ADDRESS_1);
assertThat(address05.isBounceable).isFalse();

Address address06 = Address.of(TEST_ADDRESS_0);
assertThat(address06.toString(false)).isEqualTo(TEST_ADDRESS_3);
assertThat(address06.isBounceable).isFalse();

Address address07 = Address.of(TEST_ADDRESS_1);
assertThat(address07.toString(true, true, false))
.isEqualTo("0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO");
assertThat(address07.isBounceable).isTrue();

Address address08 = Address.of(TEST_ADDRESS_1);
assertThat(address08.toString(true, true, true)).isEqualTo(TEST_ADDRESS_1);
assertThat(address08.isBounceable).isTrue();

Address address09 = Address.of(TEST_ADDRESS_1);
assertThat(address09.toString(false)).isEqualTo(TEST_ADDRESS_3);
assertThat(address09.isBounceable).isTrue();

Address address10 = Address.of(TEST_ADDRESS_3);
assertThat(address10.toString(true, true, false, true))
.isEqualTo("0QAs9VlT6S776tq3unJcP5Ogsj-ELLunLXuOb1EKcOQi4-QO");

Address address11 = Address.of(TEST_ADDRESS_3);
assertThat(address11.toString(true, true, true, true)).isEqualTo(TEST_ADDRESS_1);

Address address12 = Address.of(TEST_ADDRESS_3);
assertThat(address12.toString(false)).isEqualTo(TEST_ADDRESS_3);

Address address13 =
Address.of("-1:3333333333333333333333333333333333333333333333333333333333333333");
assertThat(address13.toString(true, false, true, false))
.isEqualTo("Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF");
assertThat(address13.toString(true, false, false, false))
.isEqualTo("Uf8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMxYA");
assertThat(Utils.bytesToHex(address13.hashPart))
.isEqualTo("3333333333333333333333333333333333333333333333333333333333333333");
assertThat(address13.hashPart.length).isEqualTo(32);
assertThat(address13.wc).isEqualTo((byte) -1);

Address address14 = Address.of(TEST_ADDRESS_4);
assertThat(address14.isTestOnly).isTrue();

assertThat(Address.isValid(TEST_ADDRESS_0)).isTrue();
assertThat(Address.isValid(TEST_ADDRESS_1)).isTrue();
assertThat(Address.isValid(TEST_ADDRESS_3)).isTrue();
assertThat(Address.isValid(TEST_ADDRESS_4)).isTrue();
assertThat(Address.isValid("bad_address")).isFalse();
}

@Test
public void testBadAddress() {
assertThrows(
Error.class,
() -> {
Address.of("");
Address.of("bad_input");
Address.of("kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYInz");
Address.of("ov_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYMg3");
Address.of("0:8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15:KsQHFLbKSMiYMg3");
});
}

@Test
public void testCompareAddress() {
Address a = Address.of(TEST_ADDRESS_0);
Address b = Address.of(TEST_ADDRESS_4);
assertThat(a).isNotEqualTo(b);

b = Address.of(TEST_ADDRESS_1);
assertThat(a).isNotEqualTo(b);
}

/**
* Save address to file in 36-byte format
*/
@Test
public void testSaveAddress() throws IOException {
// wc 0
Address address01 = Address.of(TEST_ADDRESS_0);
log.info("full address {}" , address01.toString(false));
log.info("bounceable address {}", address01.toString(true, true, true));
log.info("non-bounceable address {}", address01.toString(true, true, false));

address01.saveToFile("test0.addr");

// wc -1
Address address02 = Address.of(TEST_ADDRESS_5);
log.info("full address {} ", address02.toString(false));
log.info("bounceable address {}", address02.toString(true, true, true, true));
log.info("non-bounceable address {}", address02.toString(true, true, false, true));

address02.saveToFile("test1.addr");
}

@Test
public void testIsWallet() {

assertThat(Address.of(TEST_ADDRESS_0).isWallet).isTrue();
// assertThat(Address.of(TEST_ADDRESS_1).isWallet).isTrue();
assertThat(Address.of(TEST_ADDRESS_3).isWallet).isTrue();
// assertThat(Address.of(TEST_ADDRESS_4).isWallet).isTrue();
assertThat(Address.of(TEST_ADDRESS_5).isWallet).isTrue();

}
}

@Test
public void testCompareAddress() {
Address a = Address.of(TEST_ADDRESS_0);
Address b = Address.of(TEST_ADDRESS_4);
assertThat(a).isNotEqualTo(b);

b = Address.of(TEST_ADDRESS_1);
assertThat(a).isNotEqualTo(b);
}

/** Save address to file in 36-byte format */
@Test
public void testSaveAddress() throws IOException {
// wc 0
Address address01 = Address.of(TEST_ADDRESS_0);
log.info("full address {}", address01.toString(false));
log.info("bounceable address {}", address01.toString(true, true, true));
log.info("non-bounceable address {}", address01.toString(true, true, false));

address01.saveToFile("test0.addr");

// wc -1
Address address02 = Address.of(TEST_ADDRESS_5);
log.info("full address {} ", address02.toString(false));
log.info("bounceable address {}", address02.toString(true, true, true, true));
log.info("non-bounceable address {}", address02.toString(true, true, false, true));

address02.saveToFile("test1.addr");
}

@Test
public void testIsWallet() {

assertThat(Address.of(TEST_ADDRESS_0).isWallet).isTrue();
// assertThat(Address.of(TEST_ADDRESS_1).isWallet).isTrue();
assertThat(Address.of(TEST_ADDRESS_3).isWallet).isTrue();
// assertThat(Address.of(TEST_ADDRESS_4).isWallet).isTrue();
assertThat(Address.of(TEST_ADDRESS_5).isWallet).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.math.BigInteger;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.ton.java.address.Address;
import org.ton.java.cell.Cell;
import org.ton.java.cell.CellBuilder;
Expand All @@ -30,7 +31,11 @@ public class MsgAddressIntStd implements MsgAddressInt {

@Override
public String toString() {
return nonNull(address) ? (workchainId + ":" + address.toString(16)) : null;
String addressStr = address.toString(16);
if (addressStr.length() != 64) {
addressStr = StringUtils.leftPad(addressStr, 64, "0");
}
return nonNull(address) ? (workchainId + ":" + addressStr) : null;
}

public Cell toCell() {
Expand Down
32 changes: 32 additions & 0 deletions cell/src/test/java/org/ton/java/tlb/TestTlbDeserialization.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.ton.java.tlb;

import static org.assertj.core.api.Assertions.assertThat;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.ton.java.tlb.types.MsgAddressIntStd;

@Slf4j
@RunWith(JUnit4.class)
public class TestTlbDeserialization {

@Test
public void testSaveAddressWithZeros() {
MsgAddressIntStd addr1 =
MsgAddressIntStd.of("0:000212646ce2585c73ad02a115cd6e5c8485dda6cccd62e1b05385ff121e5a7c");
MsgAddressIntStd addr2 =
MsgAddressIntStd.of("0QAAAhJkbOJYXHOtAqEVzW5chIXdpszNYuGwU4X_Eh5afLsu");
log.info("addr1 {}", addr1);
log.info("addr2 {}", addr2);

log.info("addr1 toAddress {}", addr1.toAddress());
log.info("addr2 toAddress {}", addr2.toAddress());

assertThat(addr1.toString())
.isEqualTo("0:000212646ce2585c73ad02a115cd6e5c8485dda6cccd62e1b05385ff121e5a7c");
assertThat(addr2.toString())
.isEqualTo("0:000212646ce2585c73ad02a115cd6e5c8485dda6cccd62e1b05385ff121e5a7c");
}
}
39 changes: 20 additions & 19 deletions cell/src/test/java/org/ton/java/tlb/TestTlbSerialization.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ton.java.tlb;

import java.math.BigInteger;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -8,30 +9,30 @@
import org.ton.java.tlb.types.StorageInfo;
import org.ton.java.tlb.types.StorageUsed;

import java.math.BigInteger;

@Slf4j
@RunWith(JUnit4.class)
public class TestTlbSerialization {
@Test
public void testLoadShardStateFromCell() {
@Test
public void testLoadShardStateFromCell() {

StorageUsed storageUsed = StorageUsed.builder()
.bitsUsed(BigInteger.valueOf(5))
.cellsUsed(BigInteger.valueOf(3))
.publicCellsUsed(BigInteger.valueOf(3))
.build();
StorageUsed storageUsed =
StorageUsed.builder()
.bitsUsed(BigInteger.valueOf(5))
.cellsUsed(BigInteger.valueOf(3))
.publicCellsUsed(BigInteger.valueOf(3))
.build();

StorageInfo storageInfo = StorageInfo.builder()
.storageUsed(storageUsed)
.lastPaid(1709674914)
.duePayment(BigInteger.valueOf(12))
.build();
StorageInfo storageInfo =
StorageInfo.builder()
.storageUsed(storageUsed)
.lastPaid(1709674914)
.duePayment(BigInteger.valueOf(12))
.build();

Cell serializedStorageInfo = storageInfo.toCell();
Cell serializedStorageInfo = storageInfo.toCell();

log.info("serializedStorageInfo Cell {}", serializedStorageInfo.print());
log.info("serializedStorageInfo Cell {}", serializedStorageInfo.toHex());
log.info("serializedStorageInfo Struct {}", storageInfo);
}
log.info("serializedStorageInfo Cell {}", serializedStorageInfo.print());
log.info("serializedStorageInfo Cell {}", serializedStorageInfo.toHex());
log.info("serializedStorageInfo Struct {}", storageInfo);
}
}
Loading

0 comments on commit dc588e0

Please sign in to comment.