-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into leo/rlp-account
- Loading branch information
Showing
7 changed files
with
139 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Proving premine state in block 0. Has a tree depth of 4 | ||
block_no = "0" | ||
address = ['0x8b', '0x50', '0x5E', '0x28', '0x71', '0xF7', '0xdE', '0xb7', '0xa6', '0x38', '0x95', '0x20', '0x8e', '0x82', '0x27', '0xdc', '0xAa', '0x1B', '0xff', '0x05'] | ||
state_root = ['0xd7', '0xf8', '0x97', '0x4f', '0xb5', '0xac', '0x78', '0xd9', '0xac', '0x09', '0x9b', '0x9a', '0xd5', '0x01', '0x8b', '0xed', '0xc2', '0xce', '0x0a', '0x72', '0xda', '0xd1', '0x82', '0x7a', '0x17', '0x09', '0xda', '0x30', '0x58', '0x0f', '0x05', '0x44'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/noir-ethereum-api/src/noir/oracles/server/__snapshots__/app.test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
packages/noir-ethereum-api/src/noir/oracles/server/app.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { buildOracleServer } from './app.js'; | ||
|
||
import { describe, it, expect, afterAll } from 'vitest'; | ||
|
||
describe('Oracle Server', () => { | ||
const app = buildOracleServer(); | ||
afterAll(() => { | ||
app.close(); | ||
}); | ||
|
||
it('should handle get_header request', async () => { | ||
const response = await app.inject({ | ||
method: 'POST', | ||
url: '/', | ||
payload: { | ||
method: 'get_header', | ||
params: [{ Single: { inner: '0000000000000000000000000000000000000000000000000000000000d895ce' } }], | ||
id: 2, | ||
jsonrpc: '2.0' | ||
} | ||
}); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.body).toMatchSnapshot(); | ||
}); | ||
|
||
it('should handle get_account request', async () => { | ||
const response = await app.inject({ | ||
method: 'POST', | ||
url: '/', | ||
payload: { | ||
method: 'get_account', | ||
params: [ | ||
{ Single: { inner: '0000000000000000000000000000000000000000000000000000000000d895ce' } }, | ||
{ | ||
Array: [ | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000b4' }, | ||
{ inner: '000000000000000000000000000000000000000000000000000000000000007e' }, | ||
{ inner: '000000000000000000000000000000000000000000000000000000000000003c' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000d8' }, | ||
{ inner: '0000000000000000000000000000000000000000000000000000000000000037' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000dd' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000f8' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000e4' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000c5' }, | ||
{ inner: '000000000000000000000000000000000000000000000000000000000000007f' }, | ||
{ inner: '0000000000000000000000000000000000000000000000000000000000000005' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000d7' }, | ||
{ inner: '000000000000000000000000000000000000000000000000000000000000000a' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000b8' }, | ||
{ inner: '0000000000000000000000000000000000000000000000000000000000000065' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000de' }, | ||
{ inner: '000000000000000000000000000000000000000000000000000000000000006e' }, | ||
{ inner: '0000000000000000000000000000000000000000000000000000000000000019' }, | ||
{ inner: '000000000000000000000000000000000000000000000000000000000000003b' }, | ||
{ inner: '00000000000000000000000000000000000000000000000000000000000000bb' } | ||
] | ||
} | ||
], | ||
id: 2, | ||
jsonrpc: '2.0' | ||
} | ||
}); | ||
|
||
expect(response.statusCode).toBe(200); | ||
expect(response.body).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { JSONRPCRequest, JSONRPCServer, TypedJSONRPCServer } from 'json-rpc-2.0'; | ||
import Fastify from 'fastify'; | ||
import http from 'http'; | ||
import { getHeaderHandler, getAccountHandler, JSONRPCServerMethods, ServerParams } from './handlers.js'; | ||
import { createDefaultClient } from '../../../ethereum/client.js'; | ||
|
||
const client = createDefaultClient(); | ||
|
||
const jsonRPCServer: TypedJSONRPCServer<JSONRPCServerMethods, ServerParams> = new JSONRPCServer(); | ||
const serverParams = { client }; | ||
jsonRPCServer.addMethod('get_header', getHeaderHandler); | ||
jsonRPCServer.addMethod('get_account', getAccountHandler); | ||
|
||
export function buildOracleServer(opts: Fastify.FastifyHttpOptions<http.Server> = {}): Fastify.FastifyInstance { | ||
const app = Fastify(opts); | ||
|
||
app.post('/', (request, reply) => { | ||
const jsonRPCRequest = request.body as JSONRPCRequest; | ||
request.log.info({ jsonRPCRequest }, 'Received request'); | ||
|
||
jsonRPCServer.receive(jsonRPCRequest, serverParams).then((jsonRPCResponse) => { | ||
if (jsonRPCResponse) { | ||
reply.send(jsonRPCResponse); | ||
} else { | ||
reply.status(204).send(); | ||
} | ||
}); | ||
}); | ||
|
||
return app; | ||
} |