Page MenuHomePhabricator

[token-server] Initialize a new app to manage rewards tokens
ClosedPublic

Authored by bytesofman on Feb 29 2024, 18:40.

Details

Summary

token-server will be used to

  1. Validate eligibility for token rewards for Cashtab users
  2. Send token rewards to Cashtab users (eligibility will be reset after a certain time. token rewards can only be claimed by hitting an endpoint exposed by this server from https://cashtab.com)
  3. Potential future token issuance use cases, e.g. alias tokens as NFTs

Initialize with mocha, CI integration, eslint, and README.

Stub functionality -- app connects to ChronikClientNode websocket and exposes a status endpoint.

Test Plan

npm test

confirm CI with ./contrib/teamcity/build-configurations.py token-server-tests

node index.js and observe log

From my machine after waiting for a block:

chronik-client connected to websocket hosted by wss://chronik.pay2stay.com/xec/ws
Express server started on port 3333
/status from IP: ::1, host localhost:3333
{
  type: 'Block',
  msgType: 'BLK_CONNECTED',
  blockHash: '00000000000000001da2a9a5693b38c5a330e7e3703d0effab6c28b41aa050bb',
  blockHeight: 833731
}
{
  type: 'Block',
  msgType: 'BLK_FINALIZED',
  blockHash: '00000000000000001da2a9a5693b38c5a330e7e3703d0effab6c28b41aa050bb',
  blockHeight: 833731
}

navigate to http://localhost:3333/status and view {"status":"running"}

image.png (117×300 px, 5 KB)

Confirm that ctrl+c will shut down the server

From my machine:
^Ctoken-server shut down by ctrl+c

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Add stub express functionality and tests

bytesofman edited the test plan for this revision. (Show Details)
bytesofman added inline comments.
apps/mock-chronik-client/README.md
93 ↗(On Diff #45779)

The mock-chronik-client changes are split out into D15587

contrib/teamcity/build-configurations.yml
732 ↗(On Diff #45779)

this CI implementation is relevant to this diff

The other ones are in their own diff at D15588

emack requested changes to this revision.Mar 1 2024, 12:17
emack added a subscriber: emack.
emack added inline comments.
apps/token-server/test/chronik/wsHandler.test.js
25 ↗(On Diff #45779)

can you add two extra steps in this test, one to simulate exit via SIGTERM or SIGINT, and then verify mockedChronik.wsWaitForOpenCalled is back to the false state.

This revision now requires changes to proceed.Mar 1 2024, 12:17
bytesofman marked an inline comment as done.
bytesofman added inline comments.
apps/token-server/test/chronik/wsHandler.test.js
25 ↗(On Diff #45779)

one to simulate exit via SIGTERM or SIGINT

This would not belong in the unit test. Would be an integration test as happens outside the scope of this function. I'm not sure if this is testable or not in the overall app, which is why I included a manual test plan for this.

then verify mockedChronik.wsWaitForOpenCalled is back to the false state.

waitForOpen has been called -- so we should not expect this to be false. wsWaitForOpenCalled is a bit of a bootleg mocked-chronik-client method. Potentially worth getting rid of it. It's only helping confirm that the dev did not make a typo while attempting to open the websocket.

Then again, I added it because it took me awhile to debug forgetting to open the websocket after building it once, so can't say it's worthless.

This revision is now accepted and ready to land.Mar 2 2024, 07:52
bytesofman marked an inline comment as done.

rebase