mirror of
https://github.com/Qortal/AT.git
synced 2025-02-19 05:35:50 +00:00
Pack/unpack MachineState between execution rounds for more realistic testing. Also, better debug output
This commit is contained in:
parent
f7e50e08cd
commit
ca7ec689f7
@ -23,6 +23,7 @@ public abstract class ExecutableTest {
|
|||||||
public int callStackSize;
|
public int callStackSize;
|
||||||
public int userStackOffset;
|
public int userStackOffset;
|
||||||
public int userStackSize;
|
public int userStackSize;
|
||||||
|
public byte[] packedState;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
@ -36,10 +37,12 @@ public abstract class ExecutableTest {
|
|||||||
codeByteBuffer = ByteBuffer.allocate(TestUtils.NUM_CODE_PAGES * MachineState.OPCODE_SIZE);
|
codeByteBuffer = ByteBuffer.allocate(TestUtils.NUM_CODE_PAGES * MachineState.OPCODE_SIZE);
|
||||||
dataByteBuffer = ByteBuffer.allocate(TestUtils.NUM_DATA_PAGES * MachineState.VALUE_SIZE);
|
dataByteBuffer = ByteBuffer.allocate(TestUtils.NUM_DATA_PAGES * MachineState.VALUE_SIZE);
|
||||||
stateByteBuffer = null;
|
stateByteBuffer = null;
|
||||||
|
packedState = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void afterTest() {
|
public void afterTest() {
|
||||||
|
packedState = null;
|
||||||
stateByteBuffer = null;
|
stateByteBuffer = null;
|
||||||
codeByteBuffer = null;
|
codeByteBuffer = null;
|
||||||
dataByteBuffer = null;
|
dataByteBuffer = null;
|
||||||
@ -52,20 +55,29 @@ public abstract class ExecutableTest {
|
|||||||
byte[] codeBytes = codeByteBuffer.array();
|
byte[] codeBytes = codeByteBuffer.array();
|
||||||
byte[] dataBytes = dataByteBuffer.array();
|
byte[] dataBytes = dataByteBuffer.array();
|
||||||
|
|
||||||
state = new MachineState(api, logger, headerBytes, codeBytes, dataBytes);
|
if (packedState == null) {
|
||||||
|
// First time
|
||||||
|
System.out.println("First execution - deploying...");
|
||||||
|
state = new MachineState(api, logger, headerBytes, codeBytes, dataBytes);
|
||||||
|
packedState = state.toBytes();
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
System.out.println("Starting execution:");
|
state = MachineState.fromBytes(api, logger, packedState, codeBytes);
|
||||||
|
|
||||||
|
System.out.println("Starting execution round!");
|
||||||
System.out.println("Current block height: " + api.getCurrentBlockHeight());
|
System.out.println("Current block height: " + api.getCurrentBlockHeight());
|
||||||
|
System.out.println("Previous balance: " + TestAPI.prettyAmount(state.getPreviousBalance()));
|
||||||
|
System.out.println("Current balance: " + TestAPI.prettyAmount(state.getCurrentBalance()));
|
||||||
|
|
||||||
// Actual execution
|
// Actual execution
|
||||||
state.execute();
|
state.execute();
|
||||||
|
|
||||||
System.out.println("After execution:");
|
System.out.println("After execution round:");
|
||||||
System.out.println("Steps: " + state.getSteps());
|
System.out.println("Steps: " + state.getSteps());
|
||||||
System.out.println("Program Counter: " + String.format("%04x", state.getProgramCounter()));
|
System.out.println(String.format("Program Counter: 0x%04x", state.getProgramCounter()));
|
||||||
System.out.println("Stop Address: " + String.format("%04x", state.getOnStopAddress()));
|
System.out.println(String.format("Stop Address: 0x%04x", state.getOnStopAddress()));
|
||||||
System.out.println("Error Address: " + (state.getOnErrorAddress() == null ? "not set" : String.format("%04x", state.getOnErrorAddress())));
|
System.out.println("Error Address: " + (state.getOnErrorAddress() == null ? "not set" : String.format("0x%04x", state.getOnErrorAddress())));
|
||||||
|
|
||||||
if (state.getIsSleeping())
|
if (state.getIsSleeping())
|
||||||
System.out.println("Sleeping until current block height (" + state.getCurrentBlockHeight() + ") reaches " + state.getSleepUntilHeight());
|
System.out.println("Sleeping until current block height (" + state.getCurrentBlockHeight() + ") reaches " + state.getSleepUntilHeight());
|
||||||
@ -81,11 +93,14 @@ public abstract class ExecutableTest {
|
|||||||
System.out.println("Frozen: " + state.getIsFrozen());
|
System.out.println("Frozen: " + state.getIsFrozen());
|
||||||
|
|
||||||
long newBalance = state.getCurrentBalance();
|
long newBalance = state.getCurrentBalance();
|
||||||
System.out.println("New balance: " + newBalance);
|
System.out.println("New balance: " + TestAPI.prettyAmount(newBalance));
|
||||||
api.setCurrentBalance(newBalance);
|
api.setCurrentBalance(newBalance);
|
||||||
|
|
||||||
// Bump block height
|
// Bump block height
|
||||||
api.bumpCurrentBlockHeight();
|
api.bumpCurrentBlockHeight();
|
||||||
|
|
||||||
|
packedState = state.toBytes();
|
||||||
|
System.out.println("Execution round finished\n");
|
||||||
} while (!onceOnly && !state.getIsFinished());
|
} while (!onceOnly && !state.getIsFinished());
|
||||||
|
|
||||||
unwrapState(state);
|
unwrapState(state);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user