From 853942fb196f5a3e592f3d2e0bac27ee64e83477 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 9 Feb 2018 09:51:29 +0100 Subject: [PATCH] vm: add tests for intpool erroneous intpool handling --- core/vm/instructions_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index f66e12ddad..54a67ab8ce 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -47,6 +47,22 @@ func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64 if actual.Cmp(expected) != 0 { t.Errorf("Testcase %d, expected %v, got %v", i, expected, actual) } + // Check pool usage + // 1.pool is not allowed to contain anything on the stack + // 2.pool is not allowed to contain the same pointers twice + if env.interpreter.intPool.pool.len() > 0 { + + poolvals := make(map[*big.Int]struct{}) + poolvals[actual] = struct{}{} + + for ;env.interpreter.intPool.pool.len() > 0;{ + key := env.interpreter.intPool.get() + if _, exist := poolvals[key]; exist{ + t.Errorf("Testcase %d, pool contains double-entry", i) + } + poolvals[key] = struct{}{} + } + } } }