diff --git a/manager/eris-mint/eris-mint_test.go b/manager/eris-mint/eris-mint_test.go index 98a03d2ff4b5abf6df26a2550dbd57e28192ad50..294c34e233db0c260c3a0b3fd5993ad789d56231 100644 --- a/manager/eris-mint/eris-mint_test.go +++ b/manager/eris-mint/eris-mint_test.go @@ -23,7 +23,7 @@ import ( ) func TestCompatibleConsensus(t *testing.T) { - // TODO: [ben] expand by constructing and elemetary testing for each listed + // TODO: [ben] expand by constructing and elementary testing for each listed // compatible consensus engine for _, listedConsensus := range compatibleConsensus { diff --git a/manager/eris-mint/pipe.go b/manager/eris-mint/pipe.go index 3783a5720ecb21f1341f6593d8c4436ad3c2cb16..265a16fa7c385d670fda67026cd96bb152e3d989 100644 --- a/manager/eris-mint/pipe.go +++ b/manager/eris-mint/pipe.go @@ -550,12 +550,12 @@ func (pipe *erisMintPipe) BroadcastTxSync(tx txs.Tx) (*rpc_tm_types.ResultBroadc func (pipe *erisMintPipe) BlockchainInfo(minHeight, maxHeight, maxBlockLookback int) (*rpc_tm_types.ResultBlockchainInfo, error) { - height := pipe.consensusEngine.Height() + latestHeight := pipe.consensusEngine.Height() if maxHeight < 1 { - maxHeight = height + maxHeight = latestHeight } else { - maxHeight = imath.MinInt(height, maxHeight) + maxHeight = imath.MinInt(latestHeight, maxHeight) } if minHeight < 1 { minHeight = imath.MaxInt(1, maxHeight-maxBlockLookback) @@ -567,5 +567,5 @@ func (pipe *erisMintPipe) BlockchainInfo(minHeight, maxHeight, blockMetas = append(blockMetas, blockMeta) } - return &rpc_tm_types.ResultBlockchainInfo{height, blockMetas}, nil + return &rpc_tm_types.ResultBlockchainInfo{latestHeight, blockMetas}, nil } diff --git a/rpc/tendermint/test/client_rpc_test.go b/rpc/tendermint/test/client_rpc_test.go index 1bb84efc2d4e2b94beb4c60fc23a115f1803bd00..1a0a725df29d089b1180435a74e9df380f243a96 100644 --- a/rpc/tendermint/test/client_rpc_test.go +++ b/rpc/tendermint/test/client_rpc_test.go @@ -57,6 +57,13 @@ func TestHTTPNameReg(t *testing.T) { testNameReg(t, "HTTP") } +func TestHTTPBlockchainInfo(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + testBlockchainInfo(t, "HTTP") +} + //-------------------------------------------------------------------------------- // Test the JSONRPC client @@ -102,3 +109,10 @@ func TestJSONNameReg(t *testing.T) { } testNameReg(t, "JSONRPC") } + +func TestJSONBlockchainInfo(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } + testBlockchainInfo(t, "JSONRPC") +} diff --git a/rpc/tendermint/test/tests.go b/rpc/tendermint/test/tests.go index c8fac0d627b5e60c18dad3b6b3e997893994a2b1..56ea89b2c9c14a4c70d5e36545a78917df27c599 100644 --- a/rpc/tendermint/test/tests.go +++ b/rpc/tendermint/test/tests.go @@ -153,12 +153,12 @@ func testCall(t *testing.T, typ string) { t.Fatalf("Problem broadcasting transaction: %v", err) } assert.Equal(t, uint8(1), receipt.CreatesContract, "This transaction should"+ - " create a contract") + " create a contract") assert.NotEqual(t, 0, len(receipt.TxHash), "Receipt should contain a"+ - " transaction hash") + " transaction hash") contractAddr := receipt.ContractAddr assert.NotEqual(t, 0, len(contractAddr), "Transactions claims to have"+ - " created a contract but the contract address is empty") + " created a contract but the contract address is empty") // run a call through the contract data := []byte{} @@ -303,3 +303,39 @@ Subscribe: } } } + +func testBlockchainInfo(t *testing.T, typ string) { + client := clients[typ] + wsc := newWSClient(t) + nBlocks := 4 + waitNBlocks(t, wsc, nBlocks) + time.Sleep(time.Millisecond * 200) + + resp, err := edbcli.BlockchainInfo(client, 0, 0) + if err != nil { + t.Fatalf("Failed to get blockchain info: %v", err) + } + //TODO: [Silas] reintroduce this when Tendermint changes logic to fire + // NewBlock after saving a block + // see https://github.com/tendermint/tendermint/issues/273 + //assert.Equal(t, 4, resp.LastHeight, "Last height should be 4 after waiting for first 4 blocks") + assert.Equal(t, nBlocks, len(resp.BlockMetas), + "Should see 4 BlockMetas after waiting for first 4 blocks") + + lastBlockHash := resp.BlockMetas[nBlocks-1].Hash + for i := nBlocks - 2; i >= 0; i-- { + assert.Equal(t, lastBlockHash, resp.BlockMetas[i].Header.LastBlockHash, + "Blockchain should be a hash tree!") + lastBlockHash = resp.BlockMetas[i].Hash + } + + resp, err = edbcli.BlockchainInfo(client, 1, 2) + if err != nil { + t.Fatalf("Failed to get blockchain info: %v", err) + } + + assert.Equal(t, 2, len(resp.BlockMetas), + "Should see 2 BlockMetas after extracting 2 blocks") + + fmt.Printf("%v\n", resp) +} diff --git a/rpc/tendermint/test/ws_helpers.go b/rpc/tendermint/test/ws_helpers.go index ed92bca14d5414cfb024895c69ff2a27577b1b05..a13635da789200d4e26d06360055933cdf7239f0 100644 --- a/rpc/tendermint/test/ws_helpers.go +++ b/rpc/tendermint/test/ws_helpers.go @@ -96,7 +96,7 @@ func waitNBlocks(t *testing.T, wsc *client.WSClient, n int) { runThenWaitForBlock(t, wsc, func(block *tm_types.Block) bool { i++ - return i <= n + return i >= n }, func() {}) } @@ -156,7 +156,6 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, event, ok := (*result).(*ctypes.ResultEvent) if ok && event.Event == eventid { goodCh <- event.Data - break LOOP } case err := <-wsc.ErrorsCh: errCh <- err @@ -167,11 +166,10 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, } }() - // wait for an event or timeout - timeout := time.NewTimer(timeoutSeconds * time.Second) for { select { - case <-timeout.C: + // wait for an event or timeout + case <-time.After(timeoutSeconds * time.Second*3): return waitForEventError{timeout: true} case eventData := <-goodCh: // run the check