Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
7f336259
Unverified
Commit
7f336259
authored
Jul 31, 2019
by
Péter Szilágyi
Committed by
GitHub
Jul 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19902 from karalabe/simulated-close
accounts/abi/bind: support closing a simulated backend
parents
96ab8e15
140a7e91
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
8 deletions
+48
-8
simulated.go
accounts/abi/bind/backends/simulated.go
+6
-0
simulated_test.go
accounts/abi/bind/backends/simulated_test.go
+1
-0
bind_test.go
accounts/abi/bind/bind_test.go
+33
-7
util_test.go
accounts/abi/bind/util_test.go
+1
-0
oracle_test.go
contracts/checkpointoracle/oracle_test.go
+4
-1
helper_test.go
les/helper_test.go
+3
-0
No files found.
accounts/abi/bind/backends/simulated.go
View file @
7f336259
...
@@ -88,6 +88,12 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
...
@@ -88,6 +88,12 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
return
NewSimulatedBackendWithDatabase
(
rawdb
.
NewMemoryDatabase
(),
alloc
,
gasLimit
)
return
NewSimulatedBackendWithDatabase
(
rawdb
.
NewMemoryDatabase
(),
alloc
,
gasLimit
)
}
}
// Close terminates the underlying blockchain's update loop.
func
(
b
*
SimulatedBackend
)
Close
()
error
{
b
.
blockchain
.
Stop
()
return
nil
}
// Commit imports all the pending transactions as a single block and starts a
// Commit imports all the pending transactions as a single block and starts a
// fresh new state.
// fresh new state.
func
(
b
*
SimulatedBackend
)
Commit
()
{
func
(
b
*
SimulatedBackend
)
Commit
()
{
...
...
accounts/abi/bind/backends/simulated_test.go
View file @
7f336259
...
@@ -38,6 +38,7 @@ func TestSimulatedBackend(t *testing.T) {
...
@@ -38,6 +38,7 @@ func TestSimulatedBackend(t *testing.T) {
genAlloc
[
auth
.
From
]
=
core
.
GenesisAccount
{
Balance
:
big
.
NewInt
(
9223372036854775807
)}
genAlloc
[
auth
.
From
]
=
core
.
GenesisAccount
{
Balance
:
big
.
NewInt
(
9223372036854775807
)}
sim
:=
backends
.
NewSimulatedBackend
(
genAlloc
,
gasLimit
)
sim
:=
backends
.
NewSimulatedBackend
(
genAlloc
,
gasLimit
)
defer
sim
.
Close
()
// should return an error if the tx is not found
// should return an error if the tx is not found
txHash
:=
common
.
HexToHash
(
"2"
)
txHash
:=
common
.
HexToHash
(
"2"
)
...
...
accounts/abi/bind/bind_test.go
View file @
7f336259
...
@@ -282,7 +282,9 @@ var bindTests = []struct {
...
@@ -282,7 +282,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy an interaction tester contract and call a transaction on it
// Deploy an interaction tester contract and call a transaction on it
_, _, interactor, err := DeployInteractor(auth, sim, "Deploy string")
_, _, interactor, err := DeployInteractor(auth, sim, "Deploy string")
...
@@ -334,7 +336,9 @@ var bindTests = []struct {
...
@@ -334,7 +336,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy a tuple tester contract and execute a structured call on it
// Deploy a tuple tester contract and execute a structured call on it
_, _, getter, err := DeployGetter(auth, sim)
_, _, getter, err := DeployGetter(auth, sim)
...
@@ -377,7 +381,9 @@ var bindTests = []struct {
...
@@ -377,7 +381,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy a tuple tester contract and execute a structured call on it
// Deploy a tuple tester contract and execute a structured call on it
_, _, tupler, err := DeployTupler(auth, sim)
_, _, tupler, err := DeployTupler(auth, sim)
...
@@ -432,7 +438,9 @@ var bindTests = []struct {
...
@@ -432,7 +438,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy a slice tester contract and execute a n array call on it
// Deploy a slice tester contract and execute a n array call on it
_, _, slicer, err := DeploySlicer(auth, sim)
_, _, slicer, err := DeploySlicer(auth, sim)
...
@@ -477,7 +485,9 @@ var bindTests = []struct {
...
@@ -477,7 +485,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy a default method invoker contract and execute its default method
// Deploy a default method invoker contract and execute its default method
_, _, defaulter, err := DeployDefaulter(auth, sim)
_, _, defaulter, err := DeployDefaulter(auth, sim)
...
@@ -519,7 +529,9 @@ var bindTests = []struct {
...
@@ -519,7 +529,9 @@ var bindTests = []struct {
`
,
`
,
`
`
// Create a simulator and wrap a non-deployed contract
// Create a simulator and wrap a non-deployed contract
sim := backends.NewSimulatedBackend(core.GenesisAlloc{}, uint64(10000000000))
sim := backends.NewSimulatedBackend(core.GenesisAlloc{}, uint64(10000000000))
defer sim.Close()
nonexistent, err := NewNonExistent(common.Address{}, sim)
nonexistent, err := NewNonExistent(common.Address{}, sim)
if err != nil {
if err != nil {
...
@@ -566,7 +578,9 @@ var bindTests = []struct {
...
@@ -566,7 +578,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy a funky gas pattern contract
// Deploy a funky gas pattern contract
_, _, limiter, err := DeployFunkyGasPattern(auth, sim)
_, _, limiter, err := DeployFunkyGasPattern(auth, sim)
...
@@ -613,7 +627,9 @@ var bindTests = []struct {
...
@@ -613,7 +627,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy a sender tester contract and execute a structured call on it
// Deploy a sender tester contract and execute a structured call on it
_, _, callfrom, err := DeployCallFrom(auth, sim)
_, _, callfrom, err := DeployCallFrom(auth, sim)
...
@@ -685,7 +701,9 @@ var bindTests = []struct {
...
@@ -685,7 +701,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy a underscorer tester contract and execute a structured call on it
// Deploy a underscorer tester contract and execute a structured call on it
_, _, underscorer, err := DeployUnderscorer(auth, sim)
_, _, underscorer, err := DeployUnderscorer(auth, sim)
...
@@ -776,7 +794,9 @@ var bindTests = []struct {
...
@@ -776,7 +794,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
// Deploy an eventer contract
// Deploy an eventer contract
_, _, eventer, err := DeployEventer(auth, sim)
_, _, eventer, err := DeployEventer(auth, sim)
...
@@ -963,7 +983,9 @@ var bindTests = []struct {
...
@@ -963,7 +983,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
//deploy the test contract
//deploy the test contract
_, _, testContract, err := DeployDeeplyNestedArray(auth, sim)
_, _, testContract, err := DeployDeeplyNestedArray(auth, sim)
...
@@ -1091,13 +1113,15 @@ var bindTests = []struct {
...
@@ -1091,13 +1113,15 @@ var bindTests = []struct {
`
`
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
backend := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
_, _, contract, err := DeployTuple(auth, backend)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
_, _, contract, err := DeployTuple(auth, sim)
if err != nil {
if err != nil {
t.Fatalf("deploy contract failed %v", err)
t.Fatalf("deploy contract failed %v", err)
}
}
backend
.Commit()
sim
.Commit()
check := func(a, b interface{}, errMsg string) {
check := func(a, b interface{}, errMsg string) {
if !reflect.DeepEqual(a, b) {
if !reflect.DeepEqual(a, b) {
...
@@ -1169,7 +1193,7 @@ var bindTests = []struct {
...
@@ -1169,7 +1193,7 @@ var bindTests = []struct {
if err != nil {
if err != nil {
t.Fatalf("invoke contract failed, err %v", err)
t.Fatalf("invoke contract failed, err %v", err)
}
}
backend
.Commit()
sim
.Commit()
iter, err := contract.FilterTupleEvent(nil)
iter, err := contract.FilterTupleEvent(nil)
if err != nil {
if err != nil {
...
@@ -1225,7 +1249,9 @@ var bindTests = []struct {
...
@@ -1225,7 +1249,9 @@ var bindTests = []struct {
// Generate a new random account and a funded simulator
// Generate a new random account and a funded simulator
key, _ := crypto.GenerateKey()
key, _ := crypto.GenerateKey()
auth := bind.NewKeyedTransactor(key)
auth := bind.NewKeyedTransactor(key)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000)
defer sim.Close()
//deploy the test contract
//deploy the test contract
_, _, testContract, err := DeployUseLibrary(auth, sim)
_, _, testContract, err := DeployUseLibrary(auth, sim)
...
...
accounts/abi/bind/util_test.go
View file @
7f336259
...
@@ -59,6 +59,7 @@ func TestWaitDeployed(t *testing.T) {
...
@@ -59,6 +59,7 @@ func TestWaitDeployed(t *testing.T) {
},
},
10000000
,
10000000
,
)
)
defer
backend
.
Close
()
// Create the transaction.
// Create the transaction.
tx
:=
types
.
NewContractCreation
(
0
,
big
.
NewInt
(
0
),
test
.
gas
,
big
.
NewInt
(
1
),
common
.
FromHex
(
test
.
code
))
tx
:=
types
.
NewContractCreation
(
0
,
big
.
NewInt
(
0
),
test
.
gas
,
big
.
NewInt
(
1
),
common
.
FromHex
(
test
.
code
))
...
...
contracts/checkpointoracle/oracle_test.go
View file @
7f336259
...
@@ -175,8 +175,11 @@ func TestCheckpointRegister(t *testing.T) {
...
@@ -175,8 +175,11 @@ func TestCheckpointRegister(t *testing.T) {
sort
.
Sort
(
accounts
)
sort
.
Sort
(
accounts
)
// Deploy registrar contract
// Deploy registrar contract
transactOpts
:=
bind
.
NewKeyedTransactor
(
accounts
[
0
]
.
key
)
contractBackend
:=
backends
.
NewSimulatedBackend
(
core
.
GenesisAlloc
{
accounts
[
0
]
.
addr
:
{
Balance
:
big
.
NewInt
(
1000000000
)},
accounts
[
1
]
.
addr
:
{
Balance
:
big
.
NewInt
(
1000000000
)},
accounts
[
2
]
.
addr
:
{
Balance
:
big
.
NewInt
(
1000000000
)}},
10000000
)
contractBackend
:=
backends
.
NewSimulatedBackend
(
core
.
GenesisAlloc
{
accounts
[
0
]
.
addr
:
{
Balance
:
big
.
NewInt
(
1000000000
)},
accounts
[
1
]
.
addr
:
{
Balance
:
big
.
NewInt
(
1000000000
)},
accounts
[
2
]
.
addr
:
{
Balance
:
big
.
NewInt
(
1000000000
)}},
10000000
)
defer
contractBackend
.
Close
()
transactOpts
:=
bind
.
NewKeyedTransactor
(
accounts
[
0
]
.
key
)
// 3 trusted signers, threshold 2
// 3 trusted signers, threshold 2
contractAddr
,
_
,
c
,
err
:=
contract
.
DeployCheckpointOracle
(
transactOpts
,
contractBackend
,
[]
common
.
Address
{
accounts
[
0
]
.
addr
,
accounts
[
1
]
.
addr
,
accounts
[
2
]
.
addr
},
sectionSize
,
processConfirms
,
big
.
NewInt
(
2
))
contractAddr
,
_
,
c
,
err
:=
contract
.
DeployCheckpointOracle
(
transactOpts
,
contractBackend
,
[]
common
.
Address
{
accounts
[
0
]
.
addr
,
accounts
[
1
]
.
addr
,
accounts
[
2
]
.
addr
},
sectionSize
,
processConfirms
,
big
.
NewInt
(
2
))
if
err
!=
nil
{
if
err
!=
nil
{
...
...
les/helper_test.go
View file @
7f336259
...
@@ -422,6 +422,7 @@ func newServerEnv(t *testing.T, blocks int, protocol int, waitIndexers func(*cor
...
@@ -422,6 +422,7 @@ func newServerEnv(t *testing.T, blocks int, protocol int, waitIndexers func(*cor
// Note bloom trie indexer will be closed by it parent recursively.
// Note bloom trie indexer will be closed by it parent recursively.
cIndexer
.
Close
()
cIndexer
.
Close
()
bIndexer
.
Close
()
bIndexer
.
Close
()
b
.
Close
()
}
}
}
}
...
@@ -503,5 +504,7 @@ func newClientServerEnv(t *testing.T, blocks int, protocol int, waitIndexers fun
...
@@ -503,5 +504,7 @@ func newClientServerEnv(t *testing.T, blocks int, protocol int, waitIndexers fun
bIndexer
.
Close
()
bIndexer
.
Close
()
lcIndexer
.
Close
()
lcIndexer
.
Close
()
lbIndexer
.
Close
()
lbIndexer
.
Close
()
b
.
Close
()
lb
.
Close
()
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment