diff --git a/src/data/static-nodes.json b/src/data/static-nodes.json new file mode 100644 index 000000000..8bb1b83fa --- /dev/null +++ b/src/data/static-nodes.json @@ -0,0 +1,3 @@ +[ + "enode://1bd9b8a8063810e91cd1ebcf2995ac867542d5c90dc74a6f2ada7ecd399da356d18abf3af4c84788808abde8891a75bcde4ace5a741a2ba9efe9b59dd09d5b33@46.101.97.80:30303" +] diff --git a/src/data/test-account.pk b/src/data/test-account.pk new file mode 100644 index 000000000..7ea0a9af4 --- /dev/null +++ b/src/data/test-account.pk @@ -0,0 +1 @@ +{"address":"89b50b2b26947ccad43accaef76c21d175ad85f4","crypto":{"cipher":"aes-128-ctr","ciphertext":"cc8f600a59f8c5ac3d6ab849722a6602f61de0adc5c9617a1cd014d3d9638a95","cipherparams":{"iv":"836bb6b5df64c29a84f95e7628510e71"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"4cc1f86eaa707ee37dc3b686712f09be49b7175a2046c63cfd1d7a3e7ebee8ab"},"mac":"164f2e53c67b5c85267b79e4fc8b2f9117a66b5e0546933403d85d52fffa1f52"},"id":"3ade037d-722b-467a-ad8e-2bcae28b9642","version":3,"whisperenabled":true} diff --git a/src/gethdep_test.go b/src/gethdep_test.go index 88fb94f0c..639105432 100644 --- a/src/gethdep_test.go +++ b/src/gethdep_test.go @@ -15,6 +15,13 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/whisper" "math/big" + "path/filepath" +) + +const ( + testDataDir = ".ethereumtest" + testAddress = "0x89b50b2b26947ccad43accaef76c21d175ad85f4" + testAddressPassword = "asdf" ) // TestAccountBindings makes sure we can create an account and subsequently @@ -22,9 +29,14 @@ import ( func TestAccountBindings(t *testing.T) { rpcport = 8546 // in order to avoid conflicts with running react-native app + dataDir, err := preprocessDataDir(testDataDir) + if err != nil { + glog.V(logger.Warn).Infoln("make node failed:", err) + } + // start geth node and wait for it to initialize - go createAndStartNode(".ethereumtest") - time.Sleep(5 * time.Second) + go createAndStartNode(dataDir) + time.Sleep(120 * time.Second) // LES syncs headers, so that we are up do date when it is done if currentNode == nil { t.Error("Test failed: could not start geth node") } @@ -68,15 +80,16 @@ func TestAccountBindings(t *testing.T) { t.Errorf("Test failed: Could not post to whisper: %v", err) } - // create another account - address1, _, err := createAccount("badpassword") + // import test account (with test ether on it) + err = copyFile(filepath.Join(testDataDir, "testnet", "keystore", "test-account.pk"), filepath.Join("data", "test-account.pk")) if err != nil { - fmt.Println(err.Error()) - t.Error("Test failed: could not create account") + t.Errorf("Test failed: cannot copy test account PK: %v", err) + return } + time.Sleep(2 * time.Second) - // unlock the created account - err = unlockAccount(address1, "badpassword", 3) + // unlock test account (to send ether from it) + err = unlockAccount(testAddress, testAddressPassword, 300) if err != nil { fmt.Println(err) t.Error("Test failed: could not unlock account") @@ -93,7 +106,7 @@ func TestAccountBindings(t *testing.T) { // replace transaction notification hanlder sentinel := 0 backend.SetTransactionQueueHandler(func(queuedTx les.QueuedTx) { - glog.V(logger.Info).Infof("[STATUS-GO] Tx queue value: %v\n", queuedTx.Hash.Hex()) + glog.V(logger.Info).Infof("Queued transaction hash: %v\n", queuedTx.Hash.Hex()) if err := completeTransaction(queuedTx.Hash.Hex()); err != nil { t.Errorf("Test failed: cannot complete queued transation[%s]: %v", queuedTx.Hash.Hex(), err) } @@ -106,7 +119,7 @@ func TestAccountBindings(t *testing.T) { } // send normal transaction - from, err := utils.MakeAddress(accountManager, address1) + from, err := utils.MakeAddress(accountManager, testAddress) if err != nil { t.Errorf("Test failed: Could not retrieve account from address: %v", err) } @@ -125,7 +138,7 @@ func TestAccountBindings(t *testing.T) { t.Errorf("Test failed: cannot send transaction: %v", err) } - time.Sleep(5 * time.Second) + time.Sleep(10 * time.Second) if sentinel != 1 { t.Error("Test failed: transaction was never queued or completed") } diff --git a/src/main.go b/src/main.go index 305681b37..f7413879d 100644 --- a/src/main.go +++ b/src/main.go @@ -1,10 +1,9 @@ package main import ( + "errors" "flag" "fmt" - "runtime" - "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" @@ -18,6 +17,11 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/whisper" "gopkg.in/urfave/cli.v1" + "io" + "os" + "path" + "path/filepath" + "runtime" ) const ( @@ -44,6 +48,10 @@ var ( client rpc.Client ) +var ( + ErrDataDirPreprocessingFailed = errors.New("Failed to pre-process data directory") +) + func main() { // Placeholder for anything we want to run by default @@ -54,7 +62,7 @@ func main() { // MakeNode create a geth node entity func MakeNode(inputDir string) *node.Node { - datadir = inputDir + datadir := inputDir // TODO remove admin rpcapi flag set := flag.NewFlagSet("test", 0) @@ -127,3 +135,43 @@ func makeDefaultExtra() []byte { } return extra } + +func preprocessDataDir(dataDir string) (string, error) { + testDataDir := path.Join(dataDir, "testnet") + if _, err := os.Stat(testDataDir); os.IsNotExist(err) { + if err := os.MkdirAll(testDataDir, 0755); err != nil { + return dataDir, ErrDataDirPreprocessingFailed + } + } + + // copy over static peer nodes list (LES auto-discovery is not stable yet) + dst := filepath.Join(testDataDir, "static-nodes.json") + if _, err := os.Stat(dst); os.IsNotExist(err) { + src := filepath.Join("data", "static-nodes.json") + if err := copyFile(dst, src); err != nil { + return dataDir, err + } + } + + return dataDir, nil +} + +func copyFile(dst, src string) error { + s, err := os.Open(src) + if err != nil { + return err + } + defer s.Close() + + d, err := os.Create(dst) + if err != nil { + return err + } + defer d.Close() + + if _, err := io.Copy(d, s); err != nil { + return err + } + + return nil +} diff --git a/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go b/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go index ad81891f6..e91574602 100644 --- a/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go +++ b/src/vendor/github.com/ethereum/go-ethereum/les/status_backend.go @@ -108,7 +108,7 @@ func (b *StatusBackend) CompleteQueuedTransaction(hash QueuedTxHash) error { return err } - _, err = b.txapi.CompleteQueuedTransaction(queuedTx.Context, ethapi.SendTxArgs(queuedTx.Args)) + _, err = b.txapi.CompleteQueuedTransaction(context.Background(), ethapi.SendTxArgs(queuedTx.Args)) return err }