Skip to content

Commit

Permalink
Persist test node.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Jul 28, 2021
1 parent deebc82 commit 98adf63
Showing 1 changed file with 27 additions and 104 deletions.
131 changes: 27 additions & 104 deletions client/asset/eth/rpcclient_harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,108 +3,21 @@
// This test requires that the testnet harness be running and the unix socket
// be located at $HOME/dextest/eth/gamma/node/geth.ipc
//
// These tests are expected to be run in descending as some depend on the tests before. They cannot
// be run in parallel.
// These tests are expected to be run in descending as some depend on the tests
// before. They cannot be run in parallel.
//
// TODO: Occasionally tests will fail with "timed out" because transactions are
// not being mined. If one tx is not mined, following txs from the same account
// with a higher nonce also cannot be mined, so it causes all tests after to
// fail as well. Find out why the first tx fails to be broadcast.
// NOTE: These test reuse a light node that lives in the dextest folders.
// However, when recreating the test database for every test, the nonce used
// for imported accounts is sometimes, randomly, off, which causes transactions
// to not be mined and effectively makes the node unuseable (at least before
// restarting). It also seems to have caused getting balance of an account to
// fail, and sometime the redeem and refund functions to also fail. This could
// be a problem in the future if a user restores from seed. Punting on this
// particular problem for now.
//
// TODO: Running these tests many times eventually results in all transactions
// returning "unexpeted error for test ok: exceeds block gas limit". Find out
// why that is.
//
// Other random failures that could use investigation:
//
// === RUN TestBalance
// INFO [07-22|19:22:59.273] Imported new block headers count=152 elapsed=13.003ms number=344 hash=62f3d2..092dbc age=1h3m49s
// INFO [07-22|19:22:59.309] Imported new block headers count=2 elapsed="195.066µs" number=346 hash=d8fdec..bb55c2 age=1h3m47s
// WARN [07-22|19:23:02.157] Served eth_getBalance reqid=12 t=3.000772099s err="getDeleteStateObject (2b84c791b79ee37de042ad2fff1a253c3ce9bc27) error: no suitable peers available"
// rpcclient_harness_test.go:252: getDeleteStateObject (2b84c791b79ee37de042ad2fff1a253c3ce9bc27) error: no suitable peers available
// --- FAIL: TestBalance (3.00s)
//
// ----------------------------------------------------------------------------------------------------
//
// NOTE: May happen on ok before or after locktime.
//
// === RUN TestRedeem
// INFO [07-22|20:36:36.677] Looking for peers peercount=1 tried=3 static=1
// INFO [07-22|20:36:37.003] Imported new block headers count=1 elapsed="99.306µs" number=967 hash=02e925..b84642
// INFO [07-22|20:36:37.467] Submitted transaction hash=0x51c241ff265de32e1513f6aeba491dcf5ce1c8bc1297a240ab11c5e39363f62f from=0x2b84C791b79Ee37De042AD2ffF1A253c3ce9bc27 nonce=113 recipient=0xc26C58195deBc5E2e9864DF74ab75FEdd69330d0 value=1,000,000,000,000,000,000
// INFO [07-22|20:36:38.004] Imported new block headers count=1 elapsed="82.174µs" number=968 hash=3df9b8..006253
// INFO [07-22|20:36:39.003] Imported new block headers count=1 elapsed="100.478µs" number=969 hash=9c074c..ea162b
// INFO [07-22|20:36:40.003] Imported new block headers count=1 elapsed="94.357µs" number=970 hash=e3a897..79029d
// INFO [07-22|20:36:41.005] Imported new block headers count=1 elapsed="91.873µs" number=971 hash=3ca379..a8ad4e
// INFO [07-22|20:36:42.003] Imported new block headers count=1 elapsed="90.079µs" number=972 hash=7850ec..7915bf
// INFO [07-22|20:36:43.005] Imported new block headers count=1 elapsed="87.304µs" number=973 hash=2e100f..5d6c32
// INFO [07-22|20:36:44.003] Imported new block headers count=1 elapsed="113.994µs" number=974 hash=d375e7..1d3c4f
// INFO [07-22|20:36:45.005] Imported new block headers count=1 elapsed="85.13µs" number=975 hash=a32fa3..1b2c7f
// INFO [07-22|20:36:45.583] Submitted transaction hash=0xcfb227a021311cad7026bf0f04536ddbc9b417e391e023b7ac50ae7fa4fc6138 from=0x345853e21b1d475582E71cC269124eD5e2dD3422 nonce=30 recipient=0xc26C58195deBc5E2e9864DF74ab75FEdd69330d0 value=0
// (*types.Transaction)(0xc00054b320)({
// inner: (*types.LegacyTx)(0xc00054b260)({
// Nonce: (uint64) 30,
// GasPrice: (*big.Int)(0xc009bc50a0)(82000000000),
// Gas: (uint64) 1000000,
// To: (*common.Address)(0xc0004b6780)((len=20 cap=20) 0xc26C58195deBc5E2e9864DF74ab75FEdd69330d0),
// Value: (*big.Int)(0xc009bc5020)(0),
// Data: ([]uint8) (len=68 cap=68) {
// 00000000 b3 15 97 ad 19 b0 4b d7 86 92 ce 4b 63 4f 37 08 |......K....KcO7.|
// 00000010 e5 3e c2 64 c1 f3 44 b0 2d bf 19 e9 ab 70 57 a2 |.>.d..D.-....pW.|
// 00000020 e7 ff 71 b6 55 53 a4 af 17 eb 6e 8a 44 98 6d 97 |..q.US....n.D.m.|
// 00000030 d5 8a e3 35 08 0f f0 8b 31 8f 78 b7 a3 24 09 47 |...5....1.x..$.G|
// 00000040 ac a6 73 05 |..s.|
// },
// V: (*big.Int)(0xc009bc4fa0)(120),
// R: (*big.Int)(0xc009bc4e20)(43250630171892020267491356199781316832083307995525815821957676393523217865367),
// S: (*big.Int)(0xc009bc4ea0)(9700400057119714330402052450040760603012018937638749971416620527387734954049)
// }),
// time: (time.Time) 2021-07-22 20:36:45.583228788 +0900 JST m=+18.925814505,
// hash: (atomic.Value) {
// v: (interface {}) <nil>
// },
// size: (atomic.Value) {
// v: (interface {}) <nil>
// },
// from: (atomic.Value) {
// v: (interface {}) <nil>
// }
// })
// INFO [07-22|20:36:46.004] Imported new block headers count=1 elapsed="95.89µs" number=976 hash=09893b..40897a
// (*types.Receipt)(0xc0001b0000)({
// Type: (uint8) 0,
// PostState: ([]uint8) <nil>,
// Status: (uint64) 1,
// CumulativeGasUsed: (uint64) 61793,
// Bloom: (types.Bloom) (len=256 cap=256) {
// 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// 000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
// },
// Logs: ([]*types.Log) {
// },
// TxHash: (common.Hash) (len=32 cap=32) 0xcfb227a021311cad7026bf0f04536ddbc9b417e391e023b7ac50ae7fa4fc6138,
// ContractAddress: (common.Address) (len=20 cap=20) 0x0000000000000000000000000000000000000000,
// GasUsed: (uint64) 61793,
// BlockHash: (common.Hash) (len=32 cap=32) 0x09893bf05954ed3c1218a240851123faa4a4b6a1ce441b7b8087be812540897a,
// BlockNumber: (*big.Int)(0xc009c7dda0)(976),
// TransactionIndex: (uint) 0
// })
// rpcclient_harness_test.go:567: unexpeted balance change for test ok before locktime: want 11018877295774000000000 got 11018875573773997899999
// --- FAIL: TestRedeem (10.28s)

package eth

Expand Down Expand Up @@ -141,6 +54,7 @@ var (
gasPrice = big.NewInt(82e9)
homeDir = os.Getenv("HOME")
contractAddrFile = filepath.Join(homeDir, "dextest", "eth", "contract_addr.txt")
testDir = filepath.Join(homeDir, "dextest", "eth", "client_rpc_tests")
alphaNodeDir = filepath.Join(homeDir, "dextest", "eth", "alpha", "node")
ethClient = new(rpcclient)
ctx context.Context
Expand Down Expand Up @@ -199,12 +113,15 @@ func TestMain(m *testing.M) {
cancel()
ethClient.shutdown()
}()
tmpDir, err := ioutil.TempDir("", "dextest")
if err != nil {
fmt.Printf("error creating temp dir: %v\n", err)
os.Exit(1)
// Create dir if none yet exists. This persists for the life of the
// testing harness.
if _, err := os.Stat(testDir); os.IsNotExist(err) {
err := os.Mkdir(testDir, 0755)
if err != nil {
fmt.Printf("error creating temp dir: %v\n", err)
os.Exit(1)
}
}
defer os.RemoveAll(tmpDir)
addrBytes, err := ioutil.ReadFile(contractAddrFile)
if err != nil {
fmt.Printf("error reading contract address: %v\n", err)
Expand All @@ -218,15 +135,15 @@ func TestMain(m *testing.M) {
addrBytes = addrBytes[:addrLen-1]
fmt.Printf("Contract address is %v\n", string(addrBytes))
settings := map[string]string{
"appdir": tmpDir,
"appdir": testDir,
"nodelistenaddr": "localhost:30355",
}
wallet, err := NewWallet(&asset.WalletConfig{Settings: settings}, tLogger, dex.Simnet)
if err != nil {
fmt.Printf("error starting node: %v\n", err)
os.Exit(1)
}
fmt.Printf("Node created at: %v\n", tmpDir)
fmt.Printf("Node created at: %v\n", testDir)
defer func() {
wallet.internalNode.Close()
wallet.internalNode.Wait()
Expand Down Expand Up @@ -300,6 +217,12 @@ func TestBlock(t *testing.T) {
}

func TestImportAccounts(t *testing.T) {
// Unable to import a second time.
accts := ethClient.accounts()
if len(accts) > 1 {
fmt.Println("Skipping TestImportAccounts because accounts are already imported.")
t.Skip()
}
// The address of this will be 2b84C791b79Ee37De042AD2ffF1A253c3ce9bc27.
privB, err := hex.DecodeString("9447129055a25c8496fca9e5ee1b9463e47e6043ff0c288d07169e8284860e34")
if err != nil {
Expand Down

0 comments on commit 98adf63

Please sign in to comment.