mirror of https://github.com/ethereum/go-ethereum
cmd/evm: add tests for evm t8n (#23507)
parent
067084feda
commit
4d88974864
@ -0,0 +1,211 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"encoding/json" |
||||
"fmt" |
||||
"os" |
||||
"reflect" |
||||
"strings" |
||||
"testing" |
||||
|
||||
"github.com/docker/docker/pkg/reexec" |
||||
"github.com/ethereum/go-ethereum/internal/cmdtest" |
||||
) |
||||
|
||||
func TestMain(m *testing.M) { |
||||
// Run the app if we've been exec'd as "ethkey-test" in runEthkey.
|
||||
reexec.Register("evm-test", func() { |
||||
if err := app.Run(os.Args); err != nil { |
||||
fmt.Fprintln(os.Stderr, err) |
||||
os.Exit(1) |
||||
} |
||||
os.Exit(0) |
||||
}) |
||||
// check if we have been reexec'd
|
||||
if reexec.Init() { |
||||
return |
||||
} |
||||
os.Exit(m.Run()) |
||||
} |
||||
|
||||
type testT8n struct { |
||||
*cmdtest.TestCmd |
||||
} |
||||
|
||||
type t8nInput struct { |
||||
inAlloc string |
||||
inTxs string |
||||
inEnv string |
||||
stFork string |
||||
stReward string |
||||
} |
||||
|
||||
func (args *t8nInput) get(base string) []string { |
||||
var out []string |
||||
if opt := args.inAlloc; opt != "" { |
||||
out = append(out, "--input.alloc") |
||||
out = append(out, fmt.Sprintf("%v/%v", base, opt)) |
||||
} |
||||
if opt := args.inTxs; opt != "" { |
||||
out = append(out, "--input.txs") |
||||
out = append(out, fmt.Sprintf("%v/%v", base, opt)) |
||||
} |
||||
if opt := args.inEnv; opt != "" { |
||||
out = append(out, "--input.env") |
||||
out = append(out, fmt.Sprintf("%v/%v", base, opt)) |
||||
} |
||||
if opt := args.stFork; opt != "" { |
||||
out = append(out, "--state.fork", opt) |
||||
} |
||||
if opt := args.stReward; opt != "" { |
||||
out = append(out, "--state.reward", opt) |
||||
} |
||||
return out |
||||
} |
||||
|
||||
type t8nOutput struct { |
||||
alloc bool |
||||
result bool |
||||
body bool |
||||
} |
||||
|
||||
func (args *t8nOutput) get() (out []string) { |
||||
out = append(out, "t8n") |
||||
if args.body { |
||||
out = append(out, "--output.body", "stdout") |
||||
} else { |
||||
out = append(out, "--output.body", "") // empty means ignore
|
||||
} |
||||
if args.result { |
||||
out = append(out, "--output.result", "stdout") |
||||
} else { |
||||
out = append(out, "--output.result", "") |
||||
} |
||||
if args.alloc { |
||||
out = append(out, "--output.alloc", "stdout") |
||||
} else { |
||||
out = append(out, "--output.alloc", "") |
||||
} |
||||
return out |
||||
} |
||||
|
||||
func TestT8n(t *testing.T) { |
||||
tt := new(testT8n) |
||||
tt.TestCmd = cmdtest.NewTestCmd(t, tt) |
||||
for i, tc := range []struct { |
||||
base string |
||||
input t8nInput |
||||
output t8nOutput |
||||
expExitCode int |
||||
expOut string |
||||
}{ |
||||
{ // Test exit (3) on bad config
|
||||
base: "./testdata/1", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.json", "Frontier+1346", "", |
||||
}, |
||||
output: t8nOutput{alloc: true, result: true}, |
||||
expExitCode: 3, |
||||
}, |
||||
{ |
||||
base: "./testdata/1", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.json", "Byzantium", "", |
||||
}, |
||||
output: t8nOutput{alloc: true, result: true}, |
||||
expOut: "exp.json", |
||||
}, |
||||
{ // blockhash test
|
||||
base: "./testdata/3", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.json", "Berlin", "", |
||||
}, |
||||
output: t8nOutput{alloc: true, result: true}, |
||||
expOut: "exp.json", |
||||
}, |
||||
{ // missing blockhash test
|
||||
base: "./testdata/4", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.json", "Berlin", "", |
||||
}, |
||||
output: t8nOutput{alloc: true, result: true}, |
||||
expExitCode: 4, |
||||
}, |
||||
{ // Ommer test
|
||||
base: "./testdata/5", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.json", "Byzantium", "0x80", |
||||
}, |
||||
output: t8nOutput{alloc: true, result: true}, |
||||
expOut: "exp.json", |
||||
}, |
||||
{ // Sign json transactions
|
||||
base: "./testdata/13", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.json", "London", "", |
||||
}, |
||||
output: t8nOutput{body: true}, |
||||
expOut: "exp.json", |
||||
}, |
||||
{ // Already signed transactions
|
||||
base: "./testdata/13", |
||||
input: t8nInput{ |
||||
"alloc.json", "signed_txs.rlp", "env.json", "London", "", |
||||
}, |
||||
output: t8nOutput{result: true}, |
||||
expOut: "exp2.json", |
||||
}, |
||||
{ // Difficulty calculation - no uncles
|
||||
base: "./testdata/14", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.json", "London", "", |
||||
}, |
||||
output: t8nOutput{result: true}, |
||||
expOut: "exp.json", |
||||
}, |
||||
{ // Difficulty calculation - with uncles
|
||||
base: "./testdata/14", |
||||
input: t8nInput{ |
||||
"alloc.json", "txs.json", "env.uncles.json", "London", "", |
||||
}, |
||||
output: t8nOutput{result: true}, |
||||
expOut: "exp2.json", |
||||
}, |
||||
} { |
||||
|
||||
args := append(tc.output.get(), tc.input.get(tc.base)...) |
||||
tt.Run("evm-test", args...) |
||||
tt.Logf("args: %v\n", strings.Join(args, " ")) |
||||
// Compare the expected output, if provided
|
||||
if tc.expOut != "" { |
||||
want, err := os.ReadFile(fmt.Sprintf("%v/%v", tc.base, tc.expOut)) |
||||
if err != nil { |
||||
t.Fatalf("test %d: could not read expected output: %v", i, err) |
||||
} |
||||
have := tt.Output() |
||||
ok, err := cmpJson(have, want) |
||||
switch { |
||||
case err != nil: |
||||
t.Fatalf("test %d, json parsing failed: %v", i, err) |
||||
case !ok: |
||||
t.Fatalf("test %d: output wrong, have \n%v\nwant\n%v\n", i, string(have), string(want)) |
||||
} |
||||
} |
||||
tt.WaitExit() |
||||
if have, want := tt.ExitStatus(), tc.expExitCode; have != want { |
||||
t.Fatalf("test %d: wrong exit code, have %d, want %d", i, have, want) |
||||
} |
||||
} |
||||
} |
||||
|
||||
// cmpJson compares the JSON in two byte slices.
|
||||
func cmpJson(a, b []byte) (bool, error) { |
||||
var j, j2 interface{} |
||||
if err := json.Unmarshal(a, &j); err != nil { |
||||
return false, err |
||||
} |
||||
if err := json.Unmarshal(b, &j2); err != nil { |
||||
return false, err |
||||
} |
||||
return reflect.DeepEqual(j2, j), nil |
||||
} |
@ -0,0 +1,43 @@ |
||||
{ |
||||
"alloc": { |
||||
"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": { |
||||
"balance": "0xfeed1a9d", |
||||
"nonce": "0x1" |
||||
}, |
||||
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { |
||||
"balance": "0x5ffd4878be161d74", |
||||
"nonce": "0xac" |
||||
}, |
||||
"0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": { |
||||
"balance": "0xa410" |
||||
} |
||||
}, |
||||
"result": { |
||||
"stateRoot": "0x84208a19bc2b46ada7445180c1db162be5b39b9abc8c0a54b05d32943eae4e13", |
||||
"txRoot": "0xc4761fd7b87ff2364c7c60b6c5c8d02e522e815328aaea3f20e3b7b7ef52c42d", |
||||
"receiptRoot": "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2", |
||||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"receipts": [ |
||||
{ |
||||
"root": "0x", |
||||
"status": "0x1", |
||||
"cumulativeGasUsed": "0x5208", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"logs": null, |
||||
"transactionHash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673", |
||||
"contractAddress": "0x0000000000000000000000000000000000000000", |
||||
"gasUsed": "0x5208", |
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"transactionIndex": "0x0" |
||||
} |
||||
], |
||||
"rejected": [ |
||||
{ |
||||
"index": 1, |
||||
"error": "nonce too low: address 0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192, tx: 0 state: 1" |
||||
} |
||||
], |
||||
"currentDifficulty": "0x20000" |
||||
} |
||||
} |
@ -0,0 +1,3 @@ |
||||
{ |
||||
"body": "0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" |
||||
} |
@ -0,0 +1,38 @@ |
||||
{ |
||||
"result": { |
||||
"stateRoot": "0xe4b924a6adb5959fccf769d5b7bb2f6359e26d1e76a2443c5a91a36d826aef61", |
||||
"txRoot": "0x013509c8563d41c0ae4bf38f2d6d19fc6512a1d0d6be045079c8c9f68bf45f9d", |
||||
"receiptRoot": "0xa532a08aa9f62431d6fe5d924951b8efb86ed3c54d06fee77788c3767dd13420", |
||||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"receipts": [ |
||||
{ |
||||
"type": "0x2", |
||||
"root": "0x", |
||||
"status": "0x0", |
||||
"cumulativeGasUsed": "0x84d0", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"logs": null, |
||||
"transactionHash": "0xa98a24882ea90916c6a86da650fbc6b14238e46f0af04a131ce92be897507476", |
||||
"contractAddress": "0x0000000000000000000000000000000000000000", |
||||
"gasUsed": "0x84d0", |
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"transactionIndex": "0x0" |
||||
}, |
||||
{ |
||||
"type": "0x2", |
||||
"root": "0x", |
||||
"status": "0x0", |
||||
"cumulativeGasUsed": "0x109a0", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"logs": null, |
||||
"transactionHash": "0x36bad80acce7040c45fd32764b5c2b2d2e6f778669fb41791f73f546d56e739a", |
||||
"contractAddress": "0x0000000000000000000000000000000000000000", |
||||
"gasUsed": "0x84d0", |
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"transactionIndex": "0x1" |
||||
} |
||||
], |
||||
"currentDifficulty": "0x20000" |
||||
} |
||||
} |
@ -0,0 +1 @@ |
||||
"0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" |
@ -0,0 +1,11 @@ |
||||
{ |
||||
"result": { |
||||
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", |
||||
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"currentDifficulty": "0x2000020000000", |
||||
"receipts": [] |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
{ |
||||
"result": { |
||||
"stateRoot": "0x6f058887ca01549716789c380ede95aecc510e6d1fdc4dbf67d053c7c07f4bdc", |
||||
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"receipts": [], |
||||
"currentDifficulty": "0x1ff8020000000" |
||||
} |
||||
} |
@ -0,0 +1,4 @@ |
||||
{ |
||||
"txsRlp" : "0xf8d2b86702f864010180820fa08284d09411111111111111111111111111111111111111118080c001a0b7dfab36232379bb3d1497a4f91c1966b1f932eae3ade107bf5d723b9cb474e0a06261c359a10f2132f126d250485b90cf20f30340801244a08ef6142ab33d1904b86702f864010280820fa08284d09411111111111111111111111111111111111111118080c080a0d4ec563b6568cd42d998fc4134b36933c6568d01533b5adf08769270243c6c7fa072bf7c21eac6bbeae5143371eef26d5e279637f3bd73482b55979d76d935b1e9" |
||||
} |
||||
|
@ -0,0 +1,37 @@ |
||||
{ |
||||
"alloc": { |
||||
"0x095e7baea6a6c7c4c2dfeb977efac326af552d87": { |
||||
"code": "0x600140", |
||||
"balance": "0xde0b6b3a76586a0" |
||||
}, |
||||
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": { |
||||
"balance": "0x521f" |
||||
}, |
||||
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { |
||||
"balance": "0xde0b6b3a7622741", |
||||
"nonce": "0x1" |
||||
} |
||||
}, |
||||
"result": { |
||||
"stateRoot": "0xb7341da3f9f762a6884eaa186c32942734c146b609efee11c4b0214c44857ea1", |
||||
"txRoot": "0x75e61774a2ff58cbe32653420256c7f44bc715715a423b0b746d5c622979af6b", |
||||
"receiptRoot": "0xd0d26df80374a327c025d405ebadc752b1bbd089d864801ae78ab704bcad8086", |
||||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"receipts": [ |
||||
{ |
||||
"root": "0x", |
||||
"status": "0x1", |
||||
"cumulativeGasUsed": "0x521f", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"logs": null, |
||||
"transactionHash": "0x72fadbef39cd251a437eea619cfeda752271a5faaaa2147df012e112159ffb81", |
||||
"contractAddress": "0x0000000000000000000000000000000000000000", |
||||
"gasUsed": "0x521f", |
||||
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", |
||||
"transactionIndex": "0x0" |
||||
} |
||||
], |
||||
"currentDifficulty": "0x20000" |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
{ |
||||
"alloc": { |
||||
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": { |
||||
"balance": "0x88" |
||||
}, |
||||
"0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb": { |
||||
"balance": "0x70" |
||||
}, |
||||
"0xcccccccccccccccccccccccccccccccccccccccc": { |
||||
"balance": "0x60" |
||||
} |
||||
}, |
||||
"result": { |
||||
"stateRoot": "0xa7312add33811645c6aa65d928a1a4f49d65d448801912c069a0aa8fe9c1f393", |
||||
"txRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"receiptRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
||||
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", |
||||
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", |
||||
"receipts": [], |
||||
"currentDifficulty": "0x20000" |
||||
} |
||||
} |
Loading…
Reference in new issue