Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Nov 8, 2024
1 parent 52cc13b commit 69b6a92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions Node/Tests/NodeTests/ChainSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ struct ChainSpecTests {
for preset in GenesisPreset.allCases {
let genesis = Genesis.preset(preset)
let chainspec = try await genesis.load()
let backend = try StateBackend(InMemoryBackend(store: chainspec.getState()), config: chainspec.getConfig(), rootHash: Data32())
let backend = try StateBackend(InMemoryBackend(), config: chainspec.getConfig(), rootHash: Data32())
let state = try chainspec.getState()
try await backend.writeRaw(state.map { (key: $0.key, value: $0.value) })
let block = try chainspec.getBlock()
let config = try chainspec.getConfig()

let recentHistory = try await backend.read(StateKeys.RecentHistoryKey())
#expect(recentHistory.items.last?.headerHash == block.hash)
#expect(recentHistory?.items.last?.headerHash == block.hash)

// Verify config matches preset
#expect(config == preset.config)
Expand Down
15 changes: 9 additions & 6 deletions RPC/Sources/RPC/Handlers/ChainHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ struct ChainHandler {
throw JSONError(code: -32602, message: "Invalid block hash")
}
let state = try await source.getState(hash: data32)
guard let state else {
return JSON.null
}
// return state root for now
return [
"stateRoot": state?.stateRoot.description,
"blockHash": hash.description,
return await [
"stateRoot": state.value.stateRoot.toHexString(),
"blockHash": hash,
]
} else {
// return best block state by default
let block = try await source.getBestBlock()
let state = try await source.getState(hash: block.hash)
return [
"stateRoot": state?.stateRoot.description,
"blockHash": block.hash.description,
return await [
"stateRoot": state?.value.stateRoot.toHexString(),
"blockHash": block.hash.toHexString(),
]
}
}
Expand Down

0 comments on commit 69b6a92

Please sign in to comment.