Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add Shanghai tests by ethereum/execution-spec-tests #129

Merged
merged 57 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6d4b549
Merge pull request #40 from kaiachain/release/v1.0.1
blukat29 Jul 18, 2024
9f03292
Merge pull request #64 from kaiachain/release/v1.0.2
blukat29 Aug 19, 2024
f329a68
Merge pull request #99 from kaiachain/release/v1.0.3
blukat29 Sep 26, 2024
8cc4f45
Add downloading test files
ulbqb Oct 29, 2024
48250fe
Add state test
ulbqb Oct 30, 2024
c8c70d8
Add testing actual data
ulbqb Nov 6, 2024
1e6fbff
Add relax precomplied range for tests
ulbqb Nov 6, 2024
234ce9d
Keep legacy tests
ulbqb Nov 7, 2024
a410ec2
Simulate payload gas for Ethereum
ulbqb Nov 11, 2024
38f2f88
Simulate staking reward for Ethereum
ulbqb Nov 11, 2024
f9f70ee
Simulate root hash for Ethereum
ulbqb Nov 11, 2024
cb809eb
Make BaseFee optional, Add switching test, Simulate reward only after…
ulbqb Nov 12, 2024
1f22b56
Remove unused data
ulbqb Nov 12, 2024
629c81c
Add Merge fork
ulbqb Nov 12, 2024
dee1d14
Fix Ethereum simulation for gas price and staking reward
ulbqb Nov 12, 2024
04dd540
Revert statedb commit
ulbqb Nov 12, 2024
bf011f7
Enable tests for only Shanghai
ulbqb Nov 12, 2024
99b56c2
Fix CancunInstructionSet
ulbqb Nov 12, 2024
f137c00
Update fork config
ulbqb Nov 12, 2024
35d7f9c
Merge branch 'dev' into eip-7702-exec-tests
ulbqb Nov 12, 2024
e62559e
Fix params variables
ulbqb Nov 12, 2024
7385421
Revert unused code
ulbqb Nov 12, 2024
a1a5678
Simulate only when TestExecutionSpecState
ulbqb Nov 12, 2024
de10698
Revert test name
ulbqb Nov 12, 2024
3798751
Add skip forks
ulbqb Nov 12, 2024
bef1594
Remove an unused variable
ulbqb Nov 13, 2024
a41de19
Add initialization of flag for tests
ulbqb Nov 13, 2024
68b567d
Test TestExecutionSpecState alone
ulbqb Nov 13, 2024
04a7424
Fix for lint
ulbqb Nov 13, 2024
4d64e25
Stop using slices
ulbqb Nov 13, 2024
9046215
Fix downloading
ulbqb Nov 13, 2024
0edb0b1
Fix for lint
ulbqb Nov 14, 2024
8e95bd2
Fix for lint
ulbqb Nov 14, 2024
18fb8b0
Skip a test
ulbqb Nov 14, 2024
fe667e1
Fix for lint
ulbqb Nov 14, 2024
f52aea4
Fix for review
ulbqb Nov 14, 2024
0baf377
Fix func name
ulbqb Nov 14, 2024
5dd825a
Reuse IntrinsicGasPayload
ulbqb Nov 14, 2024
456452b
Remove Paris
ulbqb Nov 14, 2024
733f541
Fix commnets
ulbqb Nov 14, 2024
814a205
Add forgotten code
ulbqb Nov 14, 2024
e768968
Update tests/state_test.go
ulbqb Nov 14, 2024
487bd28
Update tests/state_test.go
ulbqb Nov 14, 2024
842a28d
Merge branch 'dev' into eip-7702-exec-tests
ulbqb Nov 14, 2024
b085c4e
Refactor simulateEthIntrinsicGas
ulbqb Nov 15, 2024
a5472a9
Fix isTestExecutionSpecState
ulbqb Nov 15, 2024
a72a27c
Update name
ulbqb Nov 15, 2024
04126d2
Directly set gas price
ulbqb Nov 15, 2024
9c311bd
Remove meaningless comments
ulbqb Nov 15, 2024
92ea60b
Fix MaxPriorityFeePerGas
ulbqb Nov 15, 2024
831c67d
Use Ethereum op code gas
ulbqb Nov 18, 2024
0de49b0
Stop skipping forks
ulbqb Nov 18, 2024
bc2f181
Fix chain config
ulbqb Nov 18, 2024
7e8a94b
Reset relaxPrecompileRangeForTest after TestExecutionSpecState
ulbqb Nov 19, 2024
0afb644
Update comment
ulbqb Nov 19, 2024
e98fb5f
Revert ci
ulbqb Nov 20, 2024
11899f7
Fix error handling
ulbqb Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ vendor

# used by the Makefile
/build/_workspace/
/build/cache/
/build/bin/
/klay*.zip

Expand Down Expand Up @@ -55,3 +56,5 @@ tests/testdata

# generated files but not want to include
contracts/cypress/credit.go

tests/spec-tests/
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ abigen:
@echo "Run \"$(BIN)/abigen\" to launch abigen."

test:
$(GORUN) build/ci.go test
$(GORUN) build/ci.go test -skip ^TestExecutionSpecState$$
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for testing? If so, you can simply run cd tests; go test -run=TestExecutionSpecState -v

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for a CI test. Separating tests is needed because relaxPrecompileRangeForTest and isTestExecutionSpecState affect overall.

Copy link
Contributor

@blukat29 blukat29 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are not running in parallel, you can run them altogether, ofif you defer SetRelax...(false)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#129 (comment)
I couldn't use defer because of this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use mutex, can this be reverted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hyunsooda
The problem is running TestKaiaSpecState with relaxPrecompileRangeForTest = true. This is caused by starting TestExecutionSpecState before finishing TestKaiaSpecState due to t.Parallel().

I think dropping t.Parallel() in all tests and resetting relaxPrecompileRangeForTest after finishing TestExecutionSpecState are needed so that TestKaiaSpecState (common.RelaxPrecompileRangeForTest(true)) doesn't affect other tests.

Copy link
Contributor Author

@ulbqb ulbqb Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood the spec of t.Parallel().

The test pauses when t.Parallel() is run and then next test starts. All tests which pause by t.Parallel() resume in parallel after all tests are done.

Current problem:

  1. run common.RelaxPrecompileRangeForTest(false) in TestKaiaSpecState
  2. run t.Parallel() and TestKaiaSpecState pauses
  3. run TestExecutionSpecState and common.RelaxPrecompileRangeForTest(true)
  4. resume TestKaiaSpecState with relaxPrecompileRangeForTest = true

Simple solution is running common.RelaxPrecompileRangeForTest(false) after t.Parallel() in TestKaiaSpecState. But the root cause is not running common.RelaxPrecompileRangeForTest(false) at the end of TestExecutionSpecState. So I'll implement this using Test Suite.

fixed at 7e8a94b

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thank you. The other tests seem to have been still omitted in the Makefile, don't they?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it at e98fb5f.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blukat29 @ian0371 This thread can be closed as Makefile is reverted and remains unchanged.

$(GORUN) build/ci.go test -run ^TestExecutionSpecState$$

test-seq:
$(GORUN) build/ci.go test -p 1
$(GORUN) build/ci.go test -p 1 -skip ^TestExecutionSpecState$$
$(GORUN) build/ci.go test -p 1 -run ^TestExecutionSpecState$$

test-datasync:
$(GORUN) build/ci.go test -p 1 ./datasync/...
Expand All @@ -43,7 +45,8 @@ test-node:
$(GORUN) build/ci.go test -p 1 ./node/...

test-tests:
$(GORUN) build/ci.go test -p 1 ./tests/...
$(GORUN) build/ci.go test -p 1 -skip ^TestExecutionSpecState$$ ./tests/...
$(GORUN) build/ci.go test -p 1 -run ^TestExecutionSpecState$$ ./tests/...

test-others:
$(GORUN) build/ci.go test -p 1 -exclude datasync,networks,node,tests
Expand Down
15 changes: 15 additions & 0 deletions blockchain/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,21 @@ func (s *StateDB) CreateSmartContractAccountWithKey(addr common.Address, humanRe
}
}

// SetLegacyAccountForTest is setting an account as Legacy Account to StateDB.
// SetLegacyAccountForTest should be used for only tests.
func (s *StateDB) SetLegacyAccountForTest(addr common.Address, nonce uint64, balance *big.Int, root common.Hash, codeHash []byte) {
acc := &account.LegacyAccount{
Nonce: nonce,
Balance: balance,
Root: root,
CodeHash: codeHash,
}
newobj := newObject(s, addr, acc)
s.journal.append(createObjectChange{account: &addr})
newobj.created = true
s.setStateObject(newobj)
}

func (s *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) {
so := s.getStateObject(addr)
if so == nil {
Expand Down
4 changes: 4 additions & 0 deletions blockchain/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,7 @@ func enableCancunComputationCostModification(jt *JumpTable) {
jt[LOG3].computationCost = params.Log3ComputationCostCancun
jt[LOG4].computationCost = params.Log4ComputationCostCancun
}

func ChangeGasCostForTest(jt *JumpTable, opCode OpCode, constantGas uint64) {
jt[opCode].constantGas = constantGas
}
6 changes: 6 additions & 0 deletions build/checksums.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file contains sha256 checksums of optional build dependencies.

# version:spec-tests 2.1.0
# https://github.com/ethereum/execution-spec-tests/releases
# https://github.com/ethereum/execution-spec-tests/releases/download/v2.1.0/
ca89c76851b0900bfcc3cbb9a26cbece1f3d7c64a3bed38723e914713290df6c fixtures_develop.tar.gz
41 changes: 41 additions & 0 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ var (
// Note: yakkety is unsupported because it was officially deprecated on lanchpad.
// Note: zesty is unsupported because it was officially deprecated on lanchpad.
debDistros = []string{"trusty", "xenial", "artful", "bionic"}

// This is where the tests should be unpacked.
executionSpecTestsDir = "tests/spec-tests"
)

var GOBIN, _ = filepath.Abs(filepath.Join("build", "bin"))
Expand Down Expand Up @@ -264,10 +267,17 @@ func doTest(cmdline []string) {
var (
parallel = flag.Int("p", 0, "The number of parallel test executions (default: the number of CPUs available)")
excludes = flag.String("exclude", "", "Comma-separated top-level directories to be excluded in test")
cachedir = flag.String("cachedir", "./build/cache", "directory for caching downloads")
run = flag.String("run", "", "Tests to run")
skip = flag.String("skip", "", "Tests to skip")
)
flag.CommandLine.Parse(cmdline)
env := build.Env()

// Get test fixtures.
csdb := build.MustLoadChecksums("build/checksums.txt")
downloadSpecTestFixtures(csdb, *cachedir)

packages := []string{"./..."}
if len(flag.CommandLine.Args()) > 0 {
packages = flag.CommandLine.Args()
Expand All @@ -277,6 +287,16 @@ func doTest(cmdline []string) {
packages = build.ExcludePackages(packages, strings.Split(*excludes, ","))
}

var runArgs []string
if len(*run) > 0 {
runArgs = append(runArgs, "-run", *run)
}

var skipArgs []string
if len(*skip) > 0 {
skipArgs = append(runArgs, "-skip", *skip)
}

// Run analysis tools before the tests.
build.MustRun(goTool("vet", packages...))

Expand All @@ -286,10 +306,31 @@ func doTest(cmdline []string) {
gotest.Args = append(gotest.Args, "-p", strconv.Itoa(*parallel))
}
gotest.Args = append(gotest.Args, "--timeout=30m")
gotest.Args = append(gotest.Args, runArgs...)
gotest.Args = append(gotest.Args, skipArgs...)
gotest.Args = append(gotest.Args, packages...)
build.MustRun(gotest)
}

// downloadSpecTestFixtures downloads and extracts the execution-spec-tests fixtures.
func downloadSpecTestFixtures(csdb *build.ChecksumDB, cachedir string) string {
executionSpecTestsVersion, err := build.Version(csdb, "spec-tests")
if err != nil {
log.Fatal(err)
}
ext := ".tar.gz"
base := "fixtures_develop" // TODO(MariusVanDerWijden) rename once the version becomes part of the filename
url := fmt.Sprintf("https://github.com/ethereum/execution-spec-tests/releases/download/v%s/%s%s", executionSpecTestsVersion, base, ext)
archivePath := filepath.Join(cachedir, base+ext)
if err := csdb.DownloadFile(url, archivePath); err != nil {
log.Fatal(err)
}
if err := build.ExtractArchive(archivePath, executionSpecTestsDir); err != nil {
log.Fatal(err)
}
return filepath.Join(cachedir, base)
}

func doCover(cmdline []string) {
var (
parallel = flag.Int("p", 0, "The number of parallel coverage test executions (default: the number of CPUs available)")
Expand Down
10 changes: 10 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,24 @@ func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
// If s is larger than len(h), s will be cropped from the left.
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }

var relaxPrecompileRangeForTest bool

// IsPrecompiledContractAddress returns true if the input address is in the range of precompiled contract addresses.
func IsPrecompiledContractAddress(addr Address) bool {
if relaxPrecompileRangeForTest {
return false
}
if bytes.Compare(addr.Bytes(), lastPrecompiledContractAddressHex) > 0 || addr == (Address{}) {
hyunsooda marked this conversation as resolved.
Show resolved Hide resolved
return false
}
return true
}

// Only for testing. Make sure to reset (false) after test.
func RelaxPrecompileRangeForTest(enable bool) {
relaxPrecompileRangeForTest = enable
}

// IsHexAddress verifies whether a string can represent a valid hex-encoded
// Kaia address or not.
func IsHexAddress(s string) bool {
Expand Down
26 changes: 16 additions & 10 deletions tests/gen_stenv.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 26 additions & 14 deletions tests/gen_sttransaction.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion tests/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,30 @@ var Forks = map[string]*params.ChainConfig{
"Frontier": {
ChainID: big.NewInt(1),
},
"Homestead": {
ChainID: big.NewInt(1),
},
"Byzantium": {
ChainID: big.NewInt(1),
},
"Constantinople": {
ChainID: big.NewInt(1),
},
"ConstantinopleFix": {
ChainID: big.NewInt(1),
},
"Istanbul": {
ChainID: big.NewInt(1),
},
"Berlin": {
ChainID: big.NewInt(1),
},
"London": {
ChainID: big.NewInt(1),
},
"Merge": {
hyunsooda marked this conversation as resolved.
Show resolved Hide resolved
ChainID: big.NewInt(1),
},
"Shanghai": {
ChainID: big.NewInt(1),
IstanbulCompatibleBlock: new(big.Int),
Expand All @@ -50,17 +68,33 @@ var Forks = map[string]*params.ChainConfig{
KoreCompatibleBlock: new(big.Int),
ShanghaiCompatibleBlock: new(big.Int),
},
"Prague": {
"Cancun": {
ChainID: big.NewInt(1),
IstanbulCompatibleBlock: new(big.Int),
LondonCompatibleBlock: new(big.Int),
EthTxTypeCompatibleBlock: new(big.Int),
MagmaCompatibleBlock: new(big.Int),
KoreCompatibleBlock: new(big.Int),
Kip103CompatibleBlock: new(big.Int),
ShanghaiCompatibleBlock: new(big.Int),
CancunCompatibleBlock: new(big.Int),
RandaoCompatibleBlock: new(big.Int),
KaiaCompatibleBlock: new(big.Int),
Kip160CompatibleBlock: new(big.Int),
},
"Prague": {
ChainID: big.NewInt(1),
IstanbulCompatibleBlock: new(big.Int),
LondonCompatibleBlock: new(big.Int),
EthTxTypeCompatibleBlock: new(big.Int),
MagmaCompatibleBlock: new(big.Int),
KoreCompatibleBlock: new(big.Int),
Kip103CompatibleBlock: new(big.Int),
ShanghaiCompatibleBlock: new(big.Int),
CancunCompatibleBlock: new(big.Int),
RandaoCompatibleBlock: new(big.Int),
KaiaCompatibleBlock: new(big.Int),
Kip160CompatibleBlock: new(big.Int),
PragueCompatibleBlock: new(big.Int),
},
}
Expand Down
13 changes: 7 additions & 6 deletions tests/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ import (
)

var (
baseDir = filepath.Join(".", "testdata")
blockTestDir = filepath.Join(baseDir, "BlockchainTests")
stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
transactionTestDir = filepath.Join(baseDir, "TransactionTests")
vmTestDir = filepath.Join(baseDir, "VMTests")
rlpTestDir = filepath.Join(baseDir, "RLPTests")
baseDir = filepath.Join(".", "testdata")
blockTestDir = filepath.Join(baseDir, "BlockchainTests")
stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
transactionTestDir = filepath.Join(baseDir, "TransactionTests")
vmTestDir = filepath.Join(baseDir, "VMTests")
rlpTestDir = filepath.Join(baseDir, "RLPTests")
executionSpecStateTestDir = filepath.Join(".", "spec-tests", "fixtures", "state_tests")
)

func readJSON(reader io.Reader, value interface{}) error {
Expand Down
Loading
Loading