-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Support publishing and consuming chain storage stream cells #5942
Changes from all commits
75b3e38
461204a
35db0da
52de535
6bf3878
09e165c
a427c59
ade09fb
47fe9fa
da04888
0b97c21
a167271
38ce6ea
bf1f29a
c786022
929a07c
40530fd
e4da515
5328671
2ce41da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Run scripts tests | ||
|
||
on: | ||
pull_request: | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
run-scripts-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: scripts/test/test.sh |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,10 +64,19 @@ const fakeStatusResult = { | |
}, | ||
}; | ||
|
||
export const startFakeServer = (t, fakeValues, marshaller = makeMarshal()) => { | ||
/** @typedef {Partial<import('ava').ExecutionContext<{cleanups: Array<() => void>}>> & {context}} FakeServerTestContext */ | ||
/** | ||
* @param {FakeServerTestContext} t | ||
* @param {Array<{any}>} fakeValues | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIUC, it imposes no constraints beyond existence. |
||
* @param {object} [options] | ||
* @param {Marshaller} [options.marshaller] | ||
* @param {number} [options.batchSize] count of stream-cell results per response, or 0/absent to return lone naked values | ||
*/ | ||
export const startFakeServer = (t, fakeValues, options = {}) => { | ||
const { log = console.log } = t; | ||
lastPort += 1; | ||
const PORT = lastPort; | ||
Comment on lines
77
to
78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside: this usually tells me we should listen on 0 and ask the kernel for the port we were assigned. |
||
const { marshaller = makeMarshal(), batchSize = 0 } = options; | ||
return new Promise(resolve => { | ||
log('starting http server on port', PORT); | ||
const app = express(); | ||
|
@@ -97,6 +106,8 @@ export const startFakeServer = (t, fakeValues, marshaller = makeMarshal()) => { | |
buf.set(ascii, dataPrefix.length); | ||
return toBase64(buf); | ||
}; | ||
let blockHeight = 74863; | ||
let responseValueBase64; | ||
app.post('/tendermint-rpc', (req, res) => { | ||
log('received', req.path, req.body, req.params); | ||
const reply = result => { | ||
|
@@ -114,10 +125,23 @@ export const startFakeServer = (t, fakeValues, marshaller = makeMarshal()) => { | |
break; | ||
} | ||
case 'abci_query': { | ||
const value = | ||
fakeValues.length === 0 | ||
? null | ||
: encode(marshaller.serialize(fakeValues.shift())); | ||
blockHeight += 2; | ||
const values = fakeValues.splice(0, Math.max(1, batchSize)); | ||
if (values.length > 0) { | ||
if (batchSize > 0) { | ||
// Return a JSON stream cell. | ||
const serializedValues = values.map(val => | ||
JSON.stringify(marshaller.serialize(val)), | ||
); | ||
responseValueBase64 = encode({ | ||
blockHeight: String(blockHeight - 1), | ||
values: serializedValues, | ||
}); | ||
} else { | ||
// Return a single naked value. | ||
responseValueBase64 = encode(marshaller.serialize(values[0])); | ||
} | ||
} | ||
const result = { | ||
response: { | ||
code: 0, | ||
|
@@ -127,9 +151,9 @@ export const startFakeServer = (t, fakeValues, marshaller = makeMarshal()) => { | |
key: Buffer.from( | ||
'swingset/data:mailbox.agoric1foobarbaz', | ||
).toString('base64'), | ||
value, | ||
value: responseValueBase64, | ||
proofOps: null, | ||
height: '74863', | ||
height: String(blockHeight), | ||
codespace: '', | ||
}, | ||
}; | ||
|
@@ -226,10 +250,12 @@ export const develop = async () => { | |
unserialize({ body: jsonMarshalled, slots: [] }), | ||
), | ||
); | ||
const mockT = { | ||
log: console.log, | ||
context: { cleanups: [] }, | ||
}; | ||
const mockT = /** @type {FakeServerTestContext} */ ( | ||
/** @type {unknown} */ ({ | ||
log: console.log, | ||
context: { cleanups: [] }, | ||
}) | ||
); | ||
const PORT = await startFakeServer(mockT, [...fakeValues]); | ||
console.log( | ||
`Try this in another terminal: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentionally suppressed here because we populate
cell
manually ifUnmarshal
fails to do so.