Skip to content

Commit

Permalink
tx emulator tested
Browse files Browse the repository at this point in the history
  • Loading branch information
neodix42 committed Oct 8, 2024
1 parent a22ebf5 commit 1dfdd50
Show file tree
Hide file tree
Showing 21 changed files with 501 additions and 181 deletions.
4 changes: 2 additions & 2 deletions cell/src/main/java/org/ton/java/tlb/types/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public Cell toCell() {
public static Account deserialize(CellSlice cs) {
boolean isAccount = cs.loadBit();
if (!isAccount) {
return Account.builder().isNone(false).build();
return Account.builder().isNone(true).build();

}
MsgAddressInt address = MsgAddressInt.deserialize(cs);
StorageInfo info = StorageInfo.deserialize(cs);
AccountStorage storage = AccountStorage.deserialize(cs);

return Account.builder()
.isNone(true)
.isNone(false)
.address(address)
.storageInfo(info)
.accountStorage(storage)
Expand Down
4 changes: 4 additions & 0 deletions cell/src/main/java/org/ton/java/tlb/types/ShardAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public static ShardAccount deserialize(CellSlice cs) {
.lastTransLt(cs.loadUint(64))
.build();
}

public BigInteger getBalance() {
return account.getAccountStorage().getBalance().getCoins();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class EmulateTransactionResult implements Serializable {
double elapsed_time;

ShardAccount getNewShardAccount() {
if (StringUtils.isNotEmpty(transaction)) {
if (StringUtils.isNotEmpty(shard_account)) {
return ShardAccount.deserialize(CellSlice.beginParse(Cell.fromBocBase64(shard_account)));
} else {
return ShardAccount.builder().build();
Expand All @@ -39,7 +39,7 @@ Transaction getTransaction() {
}

OutList getActions() {
if (StringUtils.isNotEmpty(transaction)) {
if (StringUtils.isNotEmpty(actions)) {
return OutList.deserialize(CellSlice.beginParse(Cell.fromBocBase64(actions)));
} else {
return OutList.builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public interface TvmEmulatorI extends Library {
*/
void tvm_emulator_destroy(long tvmEmulator);

/**
* Set config for TVM emulator
* @param tmvEmulator Pointer to TVM emulator
* @param config Pointer to Config object
* @return true in case of success, false in case of error
*/
boolean tvm_emulator_set_config_object(long tmvEmulator, long config);

/**
* Set libraries for TVM emulator
*
Expand Down
27 changes: 27 additions & 0 deletions emulator/src/main/java/org/ton/java/emulator/tx/TxEmulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ public boolean setRandSeed(String randSeedHex) {
return txEmulatorI.transaction_emulator_set_rand_seed(txEmulator, randSeedHex);
}

/**
* Set unixtime for emulation
*
* @param utime Unix timestamp
* @return true in case of success, false in case of error
*/
public boolean setUnixTime(long utime) {
return txEmulatorI.transaction_emulator_set_unixtime(txEmulator, utime);
}

/**
* Set config for emulation
*
Expand All @@ -196,6 +206,23 @@ public boolean setConfig(String configBoc) {
return txEmulatorI.transaction_emulator_set_config(txEmulator, configBoc);
}

/**
* Creates Config object from base64 encoded BoC
* @param configBoc Base64 encoded BoC serialized Config dictionary (Hashmap 32 ^Cell)
* @return Pointer to Config object or nullptr in case of error
*/
public long createConfig(String configBoc) {
return txEmulatorI.emulator_config_create(configBoc);
}

/**
* Destroy Config object
* @param config Pointer to Config object
*/
public void destroyConfig(long config) {
txEmulatorI.emulator_config_destroy(config);
}

/**
* Emulate tick-tock transaction
*
Expand Down
16 changes: 4 additions & 12 deletions emulator/src/main/java/org/ton/java/emulator/tx/TxEmulatorI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,20 @@
public interface TxEmulatorI extends Library {

/**
* @brief Creates Config object from base64 encoded BoC
* Creates Config object from base64 encoded BoC
* @param configParamBoc Base64 encoded BoC serialized Config dictionary (Hashmap 32 ^Cell)
* @return Pointer to Config object or nullptr in case of error
*/
long emulator_config_create(String configParamBoc);

/**
* @brief Set config for TVM emulator
* @param tmvEmulator Pointer to TVM emulator
* @param config Pointer to Config object
* @return true in case of success, false in case of error
*/
boolean tvm_emulator_set_config_object(long tmvEmulator, long config);

/**
* @brief Destroy Config object
* Destroy Config object
* @param config Pointer to Config object
*/
void emulator_config_destroy(long config);

/**
* @brief Get git commit hash and date of the library
* Get git commit hash and date of the library
*/
String emulator_version();

Expand Down Expand Up @@ -137,7 +129,7 @@ String transaction_emulator_emulate_tick_tock_transaction(
* @param verbosityLevel New verbosity level (0 - never, 1 - error, 2 - warning, 3 - info, 4 -
* debug)
*/
String emulator_set_verbosity_level(long txEmulator, int verbosityLevel);
void emulator_set_verbosity_level(long txEmulator, int verbosityLevel);

/**
* Set lt for emulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public static void setUpBeforeClass() {

log.info("pubKey {}", Utils.bytesToHex(keyPair.getPublicKey()));
log.info("prvKey {}", Utils.bytesToHex(keyPair.getSecretKey()));
tonlib = Tonlib.builder().testnet(true).ignoreCache(false).build();
tonlib = Tonlib.builder()
.pathToTonlibSharedLib("/home/neodix/gitProjects/ton-neodix/build/tonlib/libtonlibjson.so")
.testnet(true).ignoreCache(false).build();

walletV4R2 = WalletV4R2.builder().tonlib(tonlib).keyPair(keyPair).walletId(42).build();

Expand All @@ -75,7 +77,7 @@ public static void setUpBeforeClass() {

tvmEmulator =
TvmEmulator.builder()
.pathToEmulatorSharedLib("G:/libs/emulator.dll")
.pathToEmulatorSharedLib("/home/neodix/gitProjects/ton-neodix/build/emulator/libemulator.so")
.codeBoc(code.toBase64())
.dataBoc(data.toBase64())
.verbosityLevel(TvmVerbosityLevel.UNLIMITED)
Expand All @@ -86,7 +88,7 @@ public static void setUpBeforeClass() {
@Test
public void testInitTvmEmulator() {
// TvmEmulatorI tvmEmulatorI = Native.load("emulator.dll", TvmEmulatorI.class);
TvmEmulatorI tvmEmulatorI = Native.load("G:/libs/emulator.dll", TvmEmulatorI.class);
TvmEmulatorI tvmEmulatorI = Native.load("/home/neodix/gitProjects/ton-neodix/build/emulator/libemulator.so", TvmEmulatorI.class);
long emulator =
tvmEmulatorI.tvm_emulator_create(
walletV4R2.getStateInit().getCode().toBase64(),
Expand Down Expand Up @@ -155,7 +157,7 @@ public void testTvmEmulatorEmulateRunMethod() {
.storeRef(
CellBuilder.beginCell()
.storeRef(stack.toCell()) // c7 ^VmStack
.storeRef(getLibs()) // libs ^Cell
// .storeRef(getLibs()) // libs ^Cell
.endCell())
.storeUint(Utils.calculateMethodId("seqno"), 32) // method-id - seqno
.endCell()
Expand Down Expand Up @@ -668,7 +670,7 @@ public void testTvmEmulatorSendInternalMessageCustomContract() throws IOExceptio

tvmEmulator =
TvmEmulator.builder()
.pathToEmulatorSharedLib("G:/libs/emulator.dll")
.pathToEmulatorSharedLib("/home/neodix/gitProjects/ton-neodix/build/emulator/libemulator.so")
.codeBoc(codeCell.toBase64())
.dataBoc(dataCell.toBase64())
.verbosityLevel(TvmVerbosityLevel.UNLIMITED)
Expand Down
Loading

0 comments on commit 1dfdd50

Please sign in to comment.