-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
101 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,18 @@ | |
|
||
package bind | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/PlatONnetwork/PlatON-Go/common" | ||
) | ||
|
||
var bindTests = []struct { | ||
name string | ||
contract string | ||
|
@@ -548,10 +560,10 @@ var bindTests = []struct { | |
` | ||
"math/big" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind/backends" | ||
"github.com/PlatONnetwork/PlatON-Go/core" | ||
"github.com/PlatONnetwork/PlatON-Go/crypto" | ||
`, | ||
` | ||
// Generate a new random account and a funded simulator | ||
|
@@ -1789,17 +1801,17 @@ var bindTests = []struct { | |
abi: []string{`[{"inputs":[{"components":[{"internalType":"uint256","name":"field","type":"uint256"}],"internalType":"struct ConstructorWithStructParam.StructType","name":"st","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"}]`}, | ||
imports: ` | ||
"math/big" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/eth/ethconfig" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind/backends" | ||
"github.com/PlatONnetwork/PlatON-Go/core" | ||
"github.com/PlatONnetwork/PlatON-Go/crypto" | ||
"github.com/PlatONnetwork/PlatON-Go/eth/ethconfig" | ||
`, | ||
tester: ` | ||
var ( | ||
key, _ = crypto.GenerateKey() | ||
user, _ = bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337)) | ||
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasCeil) | ||
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasFloor) | ||
) | ||
defer sim.Close() | ||
|
@@ -1837,17 +1849,17 @@ var bindTests = []struct { | |
imports: ` | ||
"math/big" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/eth/ethconfig" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind/backends" | ||
"github.com/PlatONnetwork/PlatON-Go/core" | ||
"github.com/PlatONnetwork/PlatON-Go/crypto" | ||
"github.com/PlatONnetwork/PlatON-Go/eth/ethconfig" | ||
`, | ||
tester: ` | ||
var ( | ||
key, _ = crypto.GenerateKey() | ||
user, _ = bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337)) | ||
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasCeil) | ||
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasFloor) | ||
) | ||
defer sim.Close() | ||
|
@@ -1877,17 +1889,17 @@ var bindTests = []struct { | |
imports: ` | ||
"math/big" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/eth/ethconfig" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind" | ||
"github.com/PlatONnetwork/PlatON-Go/accounts/abi/bind/backends" | ||
"github.com/PlatONnetwork/PlatON-Go/core" | ||
"github.com/PlatONnetwork/PlatON-Go/crypto" | ||
"github.com/PlatONnetwork/PlatON-Go/eth/ethconfig" | ||
`, | ||
tester: ` | ||
var ( | ||
key, _ = crypto.GenerateKey() | ||
user, _ = bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337)) | ||
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasCeil) | ||
sim = backends.NewSimulatedBackend(core.GenesisAlloc{user.From: {Balance: big.NewInt(1000000000000000000)}}, ethconfig.Defaults.Miner.GasFloor) | ||
) | ||
_, tx, _, err := DeployRangeKeyword(user, sim) | ||
if err != nil { | ||
|
@@ -1904,7 +1916,8 @@ var bindTests = []struct { | |
|
||
// Tests that packages generated by the binder can be successfully compiled and | ||
// the requested tester run against it. | ||
/*func TestGolangBindings(t *testing.T) { | ||
func TestGolangBindings(t *testing.T) { | ||
t.Skip("need solve") | ||
// Skip the test if no Go command can be found | ||
gocmd := runtime.GOROOT() + "/bin/go" | ||
if !common.FileExist(gocmd) { | ||
|
@@ -1914,27 +1927,28 @@ var bindTests = []struct { | |
ws := t.TempDir() | ||
|
||
pkg := filepath.Join(ws, "bindtest") | ||
if err = os.MkdirAll(pkg, 0700); err != nil { | ||
if err := os.MkdirAll(pkg, 0700); err != nil { | ||
t.Fatalf("failed to create package: %v", err) | ||
} | ||
// Generate the test suite for all the contracts | ||
for i, tt := range bindTests { | ||
var types []string | ||
if tt.types != nil { | ||
types = tt.types | ||
} else { | ||
types = []string{tt.name} | ||
} | ||
// Generate the binding and create a Go source file in the workspace | ||
bind, err := Bind(types, tt.abi, tt.bytecode, tt.fsigs, "bindtest", LangGo, tt.libs, tt.aliases) | ||
if err != nil { | ||
t.Fatalf("test %d: failed to generate binding: %v", i, err) | ||
} | ||
if err = os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil { | ||
t.Fatalf("test %d: failed to write binding: %v", i, err) | ||
} | ||
// Generate the test file with the injected test code | ||
code := fmt.Sprintf(` | ||
t.Run(tt.name, func(t *testing.T) { | ||
var types []string | ||
if tt.types != nil { | ||
types = tt.types | ||
} else { | ||
types = []string{tt.name} | ||
} | ||
// Generate the binding and create a Go source file in the workspace | ||
bind, err := Bind(types, tt.abi, tt.bytecode, tt.fsigs, "bindtest", LangGo, tt.libs, tt.aliases) | ||
if err != nil { | ||
t.Fatalf("test %d: failed to generate binding: %v", i, err) | ||
} | ||
if err = os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+".go"), []byte(bind), 0600); err != nil { | ||
t.Fatalf("test %d: failed to write binding: %v", i, err) | ||
} | ||
// Generate the test file with the injected test code | ||
code := fmt.Sprintf(` | ||
package bindtest | ||
import ( | ||
|
@@ -1946,9 +1960,10 @@ var bindTests = []struct { | |
%s | ||
} | ||
`, tt.imports, tt.name, tt.tester) | ||
if err := os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0600); err != nil { | ||
t.Fatalf("test %d: failed to write tests: %v", i, err) | ||
} | ||
if err := os.WriteFile(filepath.Join(pkg, strings.ToLower(tt.name)+"_test.go"), []byte(code), 0600); err != nil { | ||
t.Fatalf("test %d: failed to write tests: %v", i, err) | ||
} | ||
}) | ||
} | ||
// Convert the package to go modules and use the current source for go-ethereum | ||
moder := exec.Command(gocmd, "mod", "init", "bindtest") | ||
|
@@ -1957,18 +1972,23 @@ var bindTests = []struct { | |
t.Fatalf("failed to convert binding test to modules: %v\n%s", err, out) | ||
} | ||
pwd, _ := os.Getwd() | ||
replacer := exec.Command(gocmd, "mod", "edit", "-replace", "github.com/PlatONnetwork/PlatON-Go="+filepath.Join(pwd, "..", "..", "..")) // Repo root | ||
replacer := exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/PlatONnetwork/[email protected]", "-replace", "github.com/PlatONnetwork/PlatON-Go="+filepath.Join(pwd, "..", "..", "..")) // Repo root | ||
replacer.Dir = pkg | ||
if out, err := replacer.CombinedOutput(); err != nil { | ||
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) | ||
} | ||
tidier := exec.Command(gocmd, "mod", "tidy") | ||
tidier.Dir = pkg | ||
if out, err := tidier.CombinedOutput(); err != nil { | ||
t.Fatalf("failed to tidy Go module file: %v\n%s", err, out) | ||
} | ||
// Test the entire package and report any failures | ||
cmd := exec.Command(gocmd, "test", "-v", "-count", "1") | ||
cmd.Dir = pkg | ||
if out, err := cmd.CombinedOutput(); err != nil { | ||
t.Fatalf("failed to run binding test: %v\n%s", err, out) | ||
} | ||
}*/ | ||
} | ||
|
||
// Tests that java binding generated by the binder is exactly matched. | ||
/*func TestJavaBindings(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.