mirror of
https://github.com/Qortal/AT.git
synced 2025-02-12 02:05:53 +00:00
API is now an abstract class instead of an Interface. This is to allow protected methods that give access to package-scoped methods and variables inside MachineState. MachineState now supports a different set of constants based on AT version. MachineState's methods and variables have had their scopes tightened up and getters/setters added where appropriate. MachineState.parseHeader() inlined into the constructor that calls it so it can set public final variables. Some reordering and additional comments in MachineState. OpCode enum entries refactored so that: a) variables provided via MachineState "state" are not explicitly passed as well b) args to each opcode are pre-fetched from the codeByteBuffer before calling and only need to be cast before use. this comes almost "for free" thanks to OpCodeParam.fetch Calling functions from OpCode now cleaner as there's no write-access to programCounter, only changing codeByteBuffer's position. Also in OpCode, state.getProgramCounter() now provides a consistent before-opcode position for branches, jumps, etc. Lots of repeated code refactored out of unit tests into ExecutableTest class. ExecutableTest also provides helper methods for examining post-execution data values, stack positions and entries.
30 lines
884 B
Java
30 lines
884 B
Java
package common;
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import org.ciyam.at.MachineState;
|
|
|
|
public class TestUtils {
|
|
|
|
// v3 constants replicated due to private cope in MachineState
|
|
public static final int CODE_PAGE_SIZE = 1;
|
|
public static final int DATA_PAGE_SIZE = MachineState.VALUE_SIZE;
|
|
public static final int CALL_STACK_PAGE_SIZE = MachineState.ADDRESS_SIZE;
|
|
public static final int USER_STACK_PAGE_SIZE = MachineState.VALUE_SIZE;
|
|
|
|
public static byte[] hexToBytes(String hex) {
|
|
byte[] output = new byte[hex.length() / 2];
|
|
byte[] converted = new BigInteger("00" + hex, 16).toByteArray();
|
|
|
|
int convertedLength = Math.min(output.length, converted.length);
|
|
int convertedStart = converted.length - convertedLength;
|
|
|
|
int outputStart = output.length - convertedLength;
|
|
|
|
System.arraycopy(converted, convertedStart, output, outputStart, convertedLength);
|
|
|
|
return output;
|
|
}
|
|
|
|
}
|