var (
expectedNextTwoOutcome, _ = PackNextTwoOutput(NextTwoOutput{big.NewInt(2), big.NewInt(3)})
expectedRepeatOutcome, _ = PackRepeatOutput("EGSEGS")
expectedAddOutcome = common.LeftPadBytes(big.NewInt(3).Bytes(), common.HashLength)
tests = map[string]testutils.PrecompileTest{
"insufficient gas for add should fail": {
Caller: common.Address{1},
InputFn: func(t testing.TB) []byte {
// CUSTOM CODE STARTS HERE
// populate test input here
testInput := AddInput{big.NewInt(1), big.NewInt(1)}
input, err := PackAdd(testInput)
require.NoError(t, err)
return input
},
SuppliedGas: AddGasCost - 1,
ReadOnly: false,
ExpectedErr: vmerrs.ErrOutOfGas.Error(),
},
"insufficient gas for nextTwo should fail": {
Caller: common.Address{1},
InputFn: func(t testing.TB) []byte {
// CUSTOM CODE STARTS HERE
// set test input to a value here
// var testInput *big.Int
testInput := big.NewInt(1)
input, err := PackNextTwo(testInput)
require.NoError(t, err)
return input
},
SuppliedGas: NextTwoGasCost - 1,
ReadOnly: false,
ExpectedErr: vmerrs.ErrOutOfGas.Error(),
},
"insufficient gas for repeat should fail": {
Caller: common.Address{1},
InputFn: func(t testing.TB) []byte {
// CUSTOM CODE STARTS HERE
// populate test input here
testInput := RepeatInput{big.NewInt(1), "EGS"}
input, err := PackRepeat(testInput)
require.NoError(t, err)
return input
},
SuppliedGas: RepeatGasCost - 1,
ReadOnly: false,
ExpectedErr: vmerrs.ErrOutOfGas.Error(),
},
"testing add": {
Caller: common.Address{1},
InputFn: func(t testing.TB) []byte {
value1 := big.NewInt(1)
value2 := big.NewInt(2)
testInput := AddInput{value1, value2}
input, err := PackAdd(testInput)
require.NoError(t, err)
return input
},
SuppliedGas: AddGasCost,
ReadOnly: true,
ExpectedRes: expectedAddOutcome,
},
"testing nextTwo": {
Caller: common.Address{1},
InputFn: func(t testing.TB) []byte {
testInput := big.NewInt(1)
input, err := PackNextTwo(testInput)
require.NoError(t, err)
return input
},
SuppliedGas: NextTwoGasCost,
ReadOnly: true,
ExpectedRes: expectedNextTwoOutcome,
},
"testing repeat": {
Caller: common.Address{1},
InputFn: func(t testing.TB) []byte {
baseString := "EGS"
timesToRepeat := big.NewInt(2)
input, err := PackRepeat(RepeatInput{timesToRepeat, baseString})
require.NoError(t, err)
return input
},
SuppliedGas: RepeatGasCost,
ReadOnly: true,
ExpectedRes: expectedRepeatOutcome,
},
}
)