Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng762 committed Nov 28, 2023
1 parent e4b6993 commit 13b70bc
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 182 deletions.
4 changes: 3 additions & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/PlatONnetwork/PlatON-Go/core/snapshotdb"
"github.com/PlatONnetwork/PlatON-Go/x/xcom"

"github.com/PlatONnetwork/PlatON-Go/log"

Expand Down Expand Up @@ -82,7 +83,8 @@ type SimulatedBackend struct {
// and uses a simulated blockchain for testing purposes.
// A simulated backend always uses chainID 1337.
func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
genesis := core.Genesis{Config: params.AllEthashProtocolChangesTest, GasLimit: gasLimit, Alloc: alloc}
xcom.GetEc(xcom.DefaultUnitTestNet)
gBlock := genesis.MustCommit(database)
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, consensus.NewFakerWithDataBase(database, gBlock), vm.Config{}, nil, nil)

Expand Down
110 changes: 65 additions & 45 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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 (
Expand All @@ -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")
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package bind
import (
"context"
"errors"
ethereum "github.com/PlatONnetwork/PlatON-Go"
"time"

ethereum "github.com/PlatONnetwork/PlatON-Go"
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/core/types"
"github.com/PlatONnetwork/PlatON-Go/log"
Expand Down
45 changes: 0 additions & 45 deletions accounts/abi/numbers.go

This file was deleted.

33 changes: 0 additions & 33 deletions accounts/abi/numbers_test.go

This file was deleted.

3 changes: 3 additions & 0 deletions accounts/scwallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ func (s *Session) walletStatus() (*walletStatus, error) {
}

// derivationPath fetches the wallet's current derivation path from the card.
//
//lint:ignore U1000 needs to be added to the console interface
func (s *Session) derivationPath() (accounts.DerivationPath, error) {
response, err := s.Channel.transmitEncrypted(claSCWallet, insStatus, statusP1Path, 0, nil)
Expand Down Expand Up @@ -996,13 +997,15 @@ func (s *Session) derive(path accounts.DerivationPath) (accounts.Account, error)
}

// keyExport contains information on an exported keypair.
//
//lint:ignore U1000 needs to be added to the console interface
type keyExport struct {
PublicKey []byte `asn1:"tag:0"`
PrivateKey []byte `asn1:"tag:1,optional"`
}

// publicKey returns the public key for the current derivation path.
//
//lint:ignore U1000 needs to be added to the console interface
func (s *Session) publicKey() ([]byte, error) {
response, err := s.Channel.transmitEncrypted(claSCWallet, insExportKey, exportP1Any, exportP2Pubkey, nil)
Expand Down
21 changes: 1 addition & 20 deletions cmd/platon/accountcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package main

import (
"fmt"

"github.com/urfave/cli/v2"
"os"

"github.com/PlatONnetwork/PlatON-Go/accounts"
"github.com/PlatONnetwork/PlatON-Go/accounts/keystore"
Expand Down Expand Up @@ -286,25 +286,6 @@ func accountUpdate(ctx *cli.Context) error {
}
return nil
}
func importWallet(ctx *cli.Context) error {
if ctx.Args().Len() != 1 {
utils.Fatalf("keyfile must be given as the only argument", "args.count", ctx.Args().Len())
}
keyfile := ctx.Args().First()
keyJSON, err := os.ReadFile(keyfile)
if err != nil {
utils.Fatalf("Could not read wallet file: %v", err)
}
stack, _ := makeConfigNode(ctx)
passphrase := utils.GetPassPhraseWithList("", false, 0, utils.MakePasswordList(ctx))
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
acct, err := ks.ImportPreSaleKey(keyJSON, passphrase)
if err != nil {
utils.Fatalf("%v", err)
}
fmt.Printf("Address: {%x}\n", acct.Address)
return nil
}

func accountImport(ctx *cli.Context) error {
if ctx.Args().Len() != 1 {
Expand Down
Loading

0 comments on commit 13b70bc

Please sign in to comment.