Skip to content

Commit 8dd8e7d

Browse files
committed
func(vm): add unit test for eip-7823
1 parent 4e1eef4 commit 8dd8e7d

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.tron.common.runtime.vm;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
import org.tron.common.utils.ByteUtil;
7+
import org.tron.core.vm.PrecompiledContracts;
8+
import org.tron.core.vm.config.ConfigLoader;
9+
import org.tron.core.vm.config.VMConfig;
10+
import org.tron.core.vm.program.Program;
11+
12+
@Slf4j
13+
public class AllowTvmOsakaTest extends VMTestBase {
14+
15+
@Test
16+
public void testEIP7823() {
17+
ConfigLoader.disable = true;
18+
VMConfig.initAllowTvmOsaka(1);
19+
20+
byte[] baseLen = new byte[32];
21+
byte[] expLen = new byte[32];
22+
byte[] modLen = new byte[32];
23+
24+
PrecompiledContracts.PrecompiledContract modExp = new PrecompiledContracts.ModExp();
25+
26+
// Valid lens
27+
try {
28+
modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
29+
} catch (Exception e) {
30+
Assert.fail();
31+
}
32+
33+
// Invalid lens
34+
try {
35+
baseLen[0] = 0x01;
36+
modExp.execute(ByteUtil.merge(baseLen, expLen, modLen));
37+
} catch (Exception e) {
38+
Assert.assertTrue(e instanceof Program.PrecompiledContractException);
39+
return;
40+
} finally {
41+
VMConfig.initAllowTvmOsaka(0);
42+
ConfigLoader.disable = false;
43+
}
44+
45+
Assert.fail();
46+
}
47+
}

0 commit comments

Comments
 (0)