Skip to content

Commit 519cbeb

Browse files
committed
test(vm): add unit test for push0 instruction
1 parent 2d7186c commit 519cbeb

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

framework/src/test/java/org/tron/common/runtime/vm/OperationsTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.tron.core.db.Manager;
2525
import org.tron.core.exception.ContractValidateException;
2626
import org.tron.core.store.StoreFactory;
27+
import org.tron.core.vm.EnergyCost;
2728
import org.tron.core.vm.JumpTable;
2829
import org.tron.core.vm.Op;
2930
import org.tron.core.vm.Operation;
@@ -40,7 +41,7 @@ public class OperationsTest {
4041

4142
private ProgramInvokeMockImpl invoke;
4243
private Program program;
43-
private final JumpTable jumpTable = OperationRegistry.newTronV10OperationSet();
44+
private final JumpTable jumpTable = OperationRegistry.getTable();
4445
private static ChainBaseManager chainBaseManager;
4546
private static String dbPath;
4647
private static TronApplicationContext context;
@@ -862,6 +863,25 @@ public void testComplexOperations() throws ContractValidateException {
862863

863864
}
864865

866+
@Test
867+
public void testPush0() throws ContractValidateException {
868+
VMConfig.initAllowTvmShangHai(1);
869+
870+
invoke = new ProgramInvokeMockImpl();
871+
Protocol.Transaction trx = Protocol.Transaction.getDefaultInstance();
872+
InternalTransaction interTrx =
873+
new InternalTransaction(trx, InternalTransaction.TrxType.TRX_UNKNOWN_TYPE);
874+
875+
byte[] op = new byte[1];
876+
op[0] = Op.PUSH0;
877+
program = new Program(op, op, invoke, interTrx);
878+
testOperations(program);
879+
Assert.assertEquals(EnergyCost.getBaseTierCost(null), program.getResult().getEnergyUsed());
880+
Assert.assertEquals(DataWord.ZERO(), program.getStack().pop());
881+
882+
VMConfig.initAllowTvmShangHai(0);
883+
}
884+
865885
private void testOperations(Program program) {
866886
try {
867887
while (!program.isStopped()) {

0 commit comments

Comments
 (0)