Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions ethereum/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
53 changes: 53 additions & 0 deletions ethereum/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions ethereum/testdata/block_0.json
Original file line number Diff line number Diff line change
@@ -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": []
}
39 changes: 39 additions & 0 deletions ethereum/testdata/block_response_0.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
}
]
}
}