From d0782cdb0dbe0fb7aed48dd16246be16ccf2c616 Mon Sep 17 00:00:00 2001 From: jangko Date: Thu, 17 Jun 2021 16:11:24 +0700 Subject: [PATCH] fixes some of graphql resolver following recent fixes in upstream hive, we also update our graphql resolvers --- ..._getBalance_invalidAccountBlockNumber.json | 6 +- ...0_eth_getBalance_invalidAccountLatest.json | 6 +- ..._getStorageAt_illegalRangeGreaterThan.json | 18 ++--- .../testcases/26_eth_getStorageAt.json | 18 ++--- .../testcases/32_eth_getTransactionCount.json | 27 +++++--- .../33_eth_getTransactionReceipt.json | 67 +++++++++++++------ nimbus/graphql/ethapi.nim | 24 ++++--- tests/graphql/queries.toml | 2 +- 8 files changed, 110 insertions(+), 58 deletions(-) diff --git a/hive_integration/nodocker/graphql/testcases/09_eth_getBalance_invalidAccountBlockNumber.json b/hive_integration/nodocker/graphql/testcases/09_eth_getBalance_invalidAccountBlockNumber.json index 3096a40b4..e22db9858 100644 --- a/hive_integration/nodocker/graphql/testcases/09_eth_getBalance_invalidAccountBlockNumber.json +++ b/hive_integration/nodocker/graphql/testcases/09_eth_getBalance_invalidAccountBlockNumber.json @@ -2,8 +2,10 @@ "request": "{block (number: 25) {account(address: \"0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef\") { balance } }}", "responses": [{ "data": { - "account": { - "balance": "0x" + "block": { + "account": { + "balance": "0x0" + } } } }], diff --git a/hive_integration/nodocker/graphql/testcases/10_eth_getBalance_invalidAccountLatest.json b/hive_integration/nodocker/graphql/testcases/10_eth_getBalance_invalidAccountLatest.json index bc80db150..885795588 100644 --- a/hive_integration/nodocker/graphql/testcases/10_eth_getBalance_invalidAccountLatest.json +++ b/hive_integration/nodocker/graphql/testcases/10_eth_getBalance_invalidAccountLatest.json @@ -2,8 +2,10 @@ "request": "{block{account(address: \"0xdeaff00ddeaff00ddeaff00ddeaff00ddeaff00d\") { balance } }}", "responses": [{ "data": { - "account": { - "balance": "0x" + "block": { + "account": { + "balance": "0x0" + } } } }], diff --git a/hive_integration/nodocker/graphql/testcases/25_eth_getStorageAt_illegalRangeGreaterThan.json b/hive_integration/nodocker/graphql/testcases/25_eth_getStorageAt_illegalRangeGreaterThan.json index a440e3205..499519276 100644 --- a/hive_integration/nodocker/graphql/testcases/25_eth_getStorageAt_illegalRangeGreaterThan.json +++ b/hive_integration/nodocker/graphql/testcases/25_eth_getStorageAt_illegalRangeGreaterThan.json @@ -1,13 +1,15 @@ { - "request" :"{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x00000000000000000000000000000021\") } }", - - "responses":[{ - "data" : { - "account" : { - "storage" : "0x0000000000000000000000000000000000000000000000000000000000000000" + "request": "{block{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x0000000000000000000000000000000000000000000000000000000000000021\") } }}", + "responses": [ + { + "data": { + "block": { + "account": { + "storage": "0x0000000000000000000000000000000000000000000000000000000000000000" + } + } } } - }], - + ], "statusCode": 200 } \ No newline at end of file diff --git a/hive_integration/nodocker/graphql/testcases/26_eth_getStorageAt.json b/hive_integration/nodocker/graphql/testcases/26_eth_getStorageAt.json index faa8f236c..57ae71911 100644 --- a/hive_integration/nodocker/graphql/testcases/26_eth_getStorageAt.json +++ b/hive_integration/nodocker/graphql/testcases/26_eth_getStorageAt.json @@ -1,13 +1,15 @@ { - "request" :"{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x00000000000000000000000000000004\") } }", - - "responses": [{ - "data" : { - "account" :{ - "storage" :"0xaabbccffffffffffffffffffffffffffffffffffffffffffffffffffffffffee" + "request": "{block{ account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { storage(slot: \"0x0000000000000000000000000000000000000000000000000000000000000004\") } }}", + "responses": [ + { + "data": { + "block": { + "account": { + "storage": "0xaabbccffffffffffffffffffffffffffffffffffffffffffffffffffffffffee" + } + } } } - }], - + ], "statusCode": 200 } \ No newline at end of file diff --git a/hive_integration/nodocker/graphql/testcases/32_eth_getTransactionCount.json b/hive_integration/nodocker/graphql/testcases/32_eth_getTransactionCount.json index 1283f72a7..79af4ce16 100644 --- a/hive_integration/nodocker/graphql/testcases/32_eth_getTransactionCount.json +++ b/hive_integration/nodocker/graphql/testcases/32_eth_getTransactionCount.json @@ -1,13 +1,24 @@ { - "request" :"{ account(address: \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\") { transactionCount } }", - - "responses": [{ - "data" : { - "account" :{ - "transactionCount" : 32 + "request": "{block{ account(address: \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\") { transactionCount } }}", + "responses": [ + { + "data": { + "block": { + "account": { + "transactionCount": 32 + } + } + } + }, + { + "data": { + "block": { + "account": { + "transactionCount": "0x20" + } + } } } - }], - + ], "statusCode": 200 } \ No newline at end of file diff --git a/hive_integration/nodocker/graphql/testcases/33_eth_getTransactionReceipt.json b/hive_integration/nodocker/graphql/testcases/33_eth_getTransactionReceipt.json index eab12a487..542144217 100644 --- a/hive_integration/nodocker/graphql/testcases/33_eth_getTransactionReceipt.json +++ b/hive_integration/nodocker/graphql/testcases/33_eth_getTransactionReceipt.json @@ -1,27 +1,52 @@ { "request": "{ transaction(hash: \"0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed\") {block{hash logsBloom} hash createdContract{address} cumulativeGasUsed gas gasUsed logs{topics} from{address} to{address} index } }", - "responses": [{ - "data": { - "transaction": { - "block": { - "hash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9", - "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - }, - "createdContract": { - "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f" - }, - "cumulativeGasUsed": 493172, - "from": { - "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" - }, - "gas": 3141592, - "gasUsed": 493172, - "hash": "0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed", - "index": 0, - "logs": [], - "to": null + "responses": [ + { + "data": { + "transaction": { + "block": { + "hash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + }, + "createdContract": { + "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f" + }, + "cumulativeGasUsed": 493172, + "from": { + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" + }, + "gas": 3141592, + "gasUsed": 493172, + "hash": "0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed", + "index": 0, + "logs": [], + "to": null + } + } + }, + { + "data": { + "transaction": { + "block": { + "hash": "0x10aaf14a53caf27552325374429d3558398a36d3682ede6603c2c6511896e9f9", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + }, + "createdContract": { + "address": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f" + }, + "cumulativeGasUsed": 493172, + "from": { + "address": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" + }, + "gas": "0x2fefd8", + "gasUsed": 493172, + "hash": "0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed", + "index": 0, + "logs": [], + "to": null + } } } - }], + ], "statusCode": 200 } diff --git a/nimbus/graphql/ethapi.nim b/nimbus/graphql/ethapi.nim index 8c7cc5124..0229839be 100644 --- a/nimbus/graphql/ethapi.nim +++ b/nimbus/graphql/ethapi.nim @@ -169,8 +169,11 @@ proc stripLeadingZeros(x: string): string = strip(x, leading = true, trailing = false, chars = {'0'}) proc bigIntNode(val: UInt256): RespResult = - let hex = stripLeadingZeros(val.toHex) - ok(Node(kind: nkString, stringVal: "0x" & hex, pos: Pos())) + if val == 0.u256: + ok(Node(kind: nkString, stringVal: "0x0", pos: Pos())) + else: + let hex = stripLeadingZeros(val.toHex) + ok(Node(kind: nkString, stringVal: "0x" & hex, pos: Pos())) proc bigIntNode(x: uint64 | int64): RespResult = # stdlib toHex is not suitable for hive @@ -218,8 +221,11 @@ proc getOmmerCount(ctx: GraphqlContextRef, ommersHash: Hash256): RespResult = proc getOmmers(ctx: GraphqlContextRef, ommersHash: Hash256): RespResult = try: let uncles = getUncles(ctx.chainDB, ommersHash) - if uncles.len == 0: - return ok(respNull()) + when false: + # EIP 1767 says no ommers == null + # but hive test case want empty array [] + if uncles.len == 0: + return ok(respNull()) var list = respList() for n in uncles: list.add headerNode(ctx, n) @@ -301,8 +307,11 @@ proc getTxByHash(ctx: GraphqlContextRef, hash: Hash256): RespResult = proc accountNode(ctx: GraphqlContextRef, header: BlockHeader, address: EthAddress): RespResult = let db = getAccountDb(ctx.chainDB, header) - if not db.accountExists(address): - return ok(respNull()) + when false: + # EIP 1767 unclear about non existent account + # but hive test case demand something + if not db.accountExists(address): + return ok(respNull()) let acc = db.getAccount(address) ok(accountNode(ctx, acc, address, db)) @@ -637,8 +646,7 @@ proc txCreatedContract(ud: RootRef, params: Args, parent: Node): RespResult {.ap return hres let h = HeaderNode(hres.get()) let db = getAccountDb(ctx.chainDB, h.header) - let creationNonce = db.getNonce(sender) - let contractAddress = generateAddress(sender, creationNonce) + let contractAddress = generateAddress(sender, tx.tx.nonce) ctx.accountNode(h.header, contractAddress) proc txLogs(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} = diff --git a/tests/graphql/queries.toml b/tests/graphql/queries.toml index e1824b448..9fd4f8622 100644 --- a/tests/graphql/queries.toml +++ b/tests/graphql/queries.toml @@ -154,7 +154,7 @@ "code":"0x", "storage":"0x0000000000000000000000000000000000000000000000000000000000000000" }, - "nullAccount":null + "nullAccount":{"__typename":"Account"} } } """