-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare tlb and cell deserialization tests - WIP
- Loading branch information
neodiX
committed
Aug 4, 2024
1 parent
ddd7788
commit 68943cd
Showing
5 changed files
with
2,045 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
cell/src/test/java/org/ton/java/TestTonSdkTestCasesTlbDeserialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.ton.java; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.ToNumberPolicy; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
import org.ton.java.cell.Cell; | ||
import org.ton.java.cell.CellBuilder; | ||
import org.ton.java.cell.CellSlice; | ||
import org.ton.java.tlb.types.InternalMessageInfo; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.net.URL; | ||
import java.nio.charset.Charset; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Slf4j | ||
@RunWith(JUnit4.class) | ||
public class TestTonSdkTestCasesTlbDeserialization { | ||
public static final String numbersTestFileUrl = "https://raw.githubusercontent.com/neodix42/ton-sdk-test-cases/main/tlb-deserialization.json"; | ||
Gson gson = new GsonBuilder().setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE).create(); | ||
String fileContentWithUseCases = IOUtils.toString(new URL(numbersTestFileUrl), Charset.defaultCharset()); | ||
TonSdkTestCases tonSdkTestCases = gson.fromJson(fileContentWithUseCases, TonSdkTestCases.class); | ||
|
||
public TestTonSdkTestCasesTlbDeserialization() throws IOException { | ||
} | ||
|
||
@Test | ||
public void testTlbDeserialization1() { | ||
|
||
String testId = "tlb-deserialization-1"; | ||
TonSdkTestCases.TestCase testCase = tonSdkTestCases.getTestCases().get(testId); | ||
|
||
String description = testCase.getDescription(); | ||
|
||
log.info("testId: {}", testId); | ||
log.info("description: {}", description); | ||
|
||
String bocAsHex = testCase.getInput().get("bocAsHex").toString(); | ||
|
||
Cell c = CellBuilder.beginCell().fromBoc("b5ee9c724101020100860001b36800bf4c6bdca25797e55d700c1a5448e2af5d1ac16f9a9628719a4e1eb2b44d85e33fd104a366f6fb17799871f82e00e4f2eb8ae6aaf6d3e0b3fb346cd0208e23725e14094ba15d20071f12260000446ee17a9b0cc8c028d8c001004d8002b374733831aac3455708e8f1d2c7f129540b982d3a5de8325bf781083a8a3d2a04a7f943813277f3ea").endCell(); | ||
InternalMessageInfo internalMessageInfo = InternalMessageInfo.deserialize(CellSlice.beginParse(c)); | ||
log.info("internalMessage {}", internalMessageInfo); | ||
|
||
Boolean ihrDisabled = Boolean.valueOf(testCase.getExpectedOutput().get("ihrDisabled").toString()); | ||
Boolean bounce = Boolean.valueOf(testCase.getExpectedOutput().get("bounce").toString()); | ||
Boolean bounced = Boolean.valueOf(testCase.getExpectedOutput().get("bounced").toString()); | ||
String sourceAddress = testCase.getExpectedOutput().get("sourceAddress").toString(); | ||
String destinationAddress = testCase.getExpectedOutput().get("destinationAddress").toString(); | ||
BigInteger valueCoins = new BigInteger(testCase.getExpectedOutput().get("valueCoins").toString()); | ||
BigInteger ihrFee = new BigInteger(testCase.getExpectedOutput().get("ihrFee").toString()); | ||
BigInteger fwdFee = new BigInteger(testCase.getExpectedOutput().get("fwdFee").toString()); | ||
BigInteger createdLt = new BigInteger(testCase.getExpectedOutput().get("createdLt").toString()); | ||
BigInteger createdAt = new BigInteger(testCase.getExpectedOutput().get("createdAt").toString()); | ||
|
||
assertThat(internalMessageInfo.getIHRDisabled()).isEqualTo(ihrDisabled); | ||
assertThat(internalMessageInfo.getBounce()).isEqualTo(bounce); | ||
assertThat(internalMessageInfo.getBounced()).isEqualTo(bounced); | ||
assertThat(internalMessageInfo.getSrcAddr().toAddress().toRaw()).isEqualTo(sourceAddress); | ||
assertThat(internalMessageInfo.getDstAddr().toAddress().toRaw()).isEqualTo(destinationAddress); | ||
assertThat(internalMessageInfo.getValue().getCoins()).isEqualTo(valueCoins); | ||
assertThat(internalMessageInfo.getIHRFee()).isEqualTo(ihrFee); | ||
assertThat(internalMessageInfo.getFwdFee()).isEqualTo(fwdFee); | ||
assertThat(internalMessageInfo.getCreatedLt()).isEqualTo(createdLt); | ||
assertThat(internalMessageInfo.getCreatedAt()).isEqualTo(createdAt.longValue()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
cell/src/test/java/org/ton/java/TestTonSdkTestCasesTlbSerialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.ton.java; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.ToNumberPolicy; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
import org.ton.java.tlb.types.MsgAddress; | ||
import org.ton.java.tlb.types.MsgAddressExtNone; | ||
import org.ton.java.tlb.types.MsgAddressExternal; | ||
import org.ton.java.utils.Utils; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.net.URL; | ||
import java.nio.charset.Charset; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Slf4j | ||
@RunWith(JUnit4.class) | ||
public class TestTonSdkTestCasesTlbSerialization { | ||
public static final String numbersTestFileUrl = "https://raw.githubusercontent.com/neodix42/ton-sdk-test-cases/main/tlb-serialization.json"; | ||
Gson gson = new GsonBuilder().setObjectToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE).create(); | ||
String fileContentWithUseCases = IOUtils.toString(new URL(numbersTestFileUrl), Charset.defaultCharset()); | ||
TonSdkTestCases tonSdkTestCases = gson.fromJson(fileContentWithUseCases, TonSdkTestCases.class); | ||
|
||
public TestTonSdkTestCasesTlbSerialization() throws IOException { | ||
} | ||
|
||
@Test | ||
public void testTlbSerialization1() { | ||
|
||
String testId = "tlb-serialization-1"; | ||
TonSdkTestCases.TestCase testCase = tonSdkTestCases.getTestCases().get(testId); | ||
|
||
String description = testCase.getDescription(); | ||
|
||
log.info("testId: {}", testId); | ||
log.info("description: {}", description); | ||
|
||
String bocAsHex = testCase.getInput().get("addr1_none").toString(); | ||
MsgAddress addr1 = MsgAddressExtNone.builder().build(); | ||
|
||
BigInteger addr2_external_len = new BigInteger(testCase.getInput().get("addr2_external_len").toString()); | ||
String addr2_external_bits = testCase.getInput().get("addr2_external_bits").toString(); | ||
|
||
MsgAddress addr2 = MsgAddressExternal.builder() | ||
.len(addr2_external_len.intValue()) | ||
.externalAddress(new BigInteger(Utils.bitStringToHex(addr2_external_bits), 16)) | ||
.build(); | ||
String bocAsHexAddr1 = testCase.getExpectedOutput().get("bocAsHexAddr1").toString(); | ||
String bocAsHexAddr2 = testCase.getExpectedOutput().get("bocAsHexAddr2").toString(); | ||
|
||
assertThat(addr1.toCell().toHex(true)).isEqualTo(bocAsHexAddr1); | ||
assertThat(addr2.toCell().toHex(true)).isEqualTo(bocAsHexAddr2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.