diff --git a/ethereum/client.go b/ethereum/client.go index 1d569bb..3d12e59 100644 --- a/ethereum/client.go +++ b/ethereum/client.go @@ -1067,14 +1067,10 @@ func (ec *Client) populateTransaction( // for a given block height. // // Source: -// https://github.com/ethereum/go-ethereum/master/consensus/ethash/consensus.go#L619-L645 +// https://github.com/ethereum/go-ethereum/blob/master/consensus/ethash/consensus.go#L646-L653 func (ec *Client) miningReward( currentBlock *big.Int, ) int64 { - if currentBlock.Int64() == int64(0) { - return big.NewInt(0).Int64() - } - blockReward := ethash.FrontierBlockReward.Int64() if ec.p.IsByzantium(currentBlock) { blockReward = ethash.ByzantiumBlockReward.Int64() diff --git a/ethereum/client_test.go b/ethereum/client_test.go index df9fcb6..e24e335 100644 --- a/ethereum/client_test.go +++ b/ethereum/client_test.go @@ -1392,6 +1392,59 @@ func TestBlock_Index(t *testing.T) { mockGraphQL.AssertExpectations(t) } +func TestBlock_FirstBlock(t *testing.T) { + mockJSONRPC := &mocks.JSONRPC{} + mockGraphQL := &mocks.GraphQL{} + + tc, err := testTraceConfig() + assert.NoError(t, err) + c := &Client{ + c: mockJSONRPC, + g: mockGraphQL, + tc: tc, + p: params.RopstenChainConfig, + traceSemaphore: semaphore.NewWeighted(100), + } + + ctx := context.Background() + mockJSONRPC.On( + "CallContext", + ctx, + mock.Anything, + "eth_getBlockByNumber", + "0x0", + true, + ).Return( + nil, + ).Run( + func(args mock.Arguments) { + r := args.Get(1).(*json.RawMessage) + + file, err := ioutil.ReadFile("testdata/block_0.json") + assert.NoError(t, err) + + *r = file + }, + ).Once() + + correctRaw, err := ioutil.ReadFile("testdata/block_response_0.json") + assert.NoError(t, err) + var correct *RosettaTypes.BlockResponse + assert.NoError(t, json.Unmarshal(correctRaw, &correct)) + + resp, err := c.Block( + ctx, + &RosettaTypes.PartialBlockIdentifier{ + Index: RosettaTypes.Int64(0), + }, + ) + assert.Equal(t, correct.Block, resp) + assert.NoError(t, err) + + mockJSONRPC.AssertExpectations(t) + mockGraphQL.AssertExpectations(t) +} + func jsonifyBlock(b *RosettaTypes.Block) (*RosettaTypes.Block, error) { bytes, err := json.Marshal(b) if err != nil { diff --git a/ethereum/testdata/block_0.json b/ethereum/testdata/block_0.json new file mode 100644 index 0000000..c5f98c0 --- /dev/null +++ b/ethereum/testdata/block_0.json @@ -0,0 +1,22 @@ +{ + "difficulty": "0x400000000", + "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa", + "gasLimit": "0x1388", + "gasUsed": "0x0", + "hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "miner": "0x0000000000000000000000000000000000000000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0000000000000042", + "number": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "size": "0x21c", + "stateRoot": "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544", + "timestamp": "0x0", + "totalDifficulty": "0x400000000", + "transactions": [], + "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "uncles": [] +} diff --git a/ethereum/testdata/block_response_0.json b/ethereum/testdata/block_response_0.json new file mode 100644 index 0000000..eb3fe1c --- /dev/null +++ b/ethereum/testdata/block_response_0.json @@ -0,0 +1,39 @@ +{ + "block":{ + "block_identifier":{ + "index":0, + "hash":"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" + }, + "parent_block_identifier":{ + "index":0, + "hash":"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" + }, + "timestamp":0, + "transactions":[ + { + "transaction_identifier":{ + "hash":"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" + }, + "operations":[ + { + "operation_identifier":{ + "index":0 + }, + "type":"MINER_REWARD", + "status":"SUCCESS", + "account":{ + "address":"0x0000000000000000000000000000000000000000" + }, + "amount":{ + "value":"5000000000000000000", + "currency":{ + "symbol":"ETH", + "decimals":18 + } + } + } + ] + } + ] + } +}