Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
HYP-13: more demands leftovers. renamed to example.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3op2 committed Nov 16, 2023
1 parent dda713b commit d69bb26
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,15 @@ Note the meaning in the API of `demandA` and `demandB` are abstract and use-case
8. `Optimiser` can now create a [`example`](http://localhost:8020/swagger/#/example/ProposeMatch2) that matches a single `demandA` with a single `demandB`. They supply their local `id` for `demandA` and `demandB`.
9. When `Optimiser` is ready for the `example` to exist on chain they [`POST /v1/example/{id}/proposal`](http://localhost:8020/swagger/#/example/ProposeMatch2OnChain).
10. Either `MemberA` or `MemberB` can accept the `example` with [`POST /v1/example/{id}/accept`](http://localhost:8000/swagger/#/example/AcceptMatch2OnChain). It doesn't matter which member accepts first.
11. Once the second member accepts, we have a successful match! The `example` state changes to `acceptedFinal` and `demandA` + `demandB` state moves to `allocated`. These demands can no longer be used in a new `example`.
11. Once the second member accepts, we have a successful match! The `example` state changes to `acceptedFinal` and `demandA` + `demandB` state moves to `allocated`. These examples can no longer be used in a new `example`.

To clear chain and database state, delete the volumes e.g. `docker compose -f docker-compose-3-persona.yml down -v`.

### Rejection paths

The previous scenario covers a 'happy path' where every member accepts each step without issue. There are also routes for communicating when something has gone wrong.

#### Commenting on demands
#### Commenting on examples

At any time a `demandA` or `demandB` can be commented on by any member by `POST`ing a single attachment to [`POST /v1/demandA/{id}/comment`](http://localhost:8000/swagger/#/demandA/CreateDemandBCommentOnChain) or [`POST /v1/demandB/{id}/comment`](http://localhost:8000/swagger/#/demandB/CreateDemandBCommentOnChain). The attachment is a file that informs the owner of the demand about anything (e.g. an issue, correction) related to the demand. A demand can be commented on multiple times and it does not change the demand's state.

Expand Down
2 changes: 1 addition & 1 deletion src/lib/indexer/__tests__/changeSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('changeSet', function () {
expect(result).to.equal(null)
})

it('should return id if token appears in demands', function () {
it('should return id if token appears in examples', function () {
const result = findLocalIdInChangeSet(findIdTestSet, 42)
expect(result).to.equal('0x02')
})
Expand Down
4 changes: 2 additions & 2 deletions src/lib/indexer/__tests__/handleEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('EventHandler', function () {
const eventHandler = new EventHandler({ db, logger, node, eventProcessors })

const baseChangeSet: ChangeSet = {
demands: new Map([
examples: new Map([
['7', { type: 'update', id: '7', latest_token_id: 1, state: 'created' }],
['8', { type: 'update', id: '8', latest_token_id: 2, state: 'created' }],
['9', { type: 'update', id: '9', latest_token_id: 3, state: 'created' }],
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('EventHandler', function () {
const eventHandler = new EventHandler({ db, logger, node, eventProcessors })

const baseChangeSet: ChangeSet = {
demands: new Map([
examples: new Map([
['7', { type: 'update', id: '7', latest_token_id: 1, state: 'created' }],
['8', { type: 'update', id: '8', latest_token_id: 2, state: 'created' }],
['9', { type: 'update', id: '9', latest_token_id: 3, state: 'created' }],
Expand Down
8 changes: 4 additions & 4 deletions src/lib/indexer/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ describe('Indexer', function () {
expect(handleBlock.secondCall.args[0]).to.equal('3-hash')
})

it('should upsert demands and example entries from changeset', async function () {
it('should upsert examples and example entries from changeset', async function () {
const db = withInitialLastProcessedBlock({ hash: '1-hash', parent: '0-hash', height: 1 })
const node = withHappyChainNode()
const handleBlock = sinon.stub().resolves({
demands: new Map([
examples: new Map([
['123', { type: 'update', id: '42' }],
['456', { type: 'update', id: '43' }],
]),
Expand Down Expand Up @@ -192,11 +192,11 @@ describe('Indexer', function () {
expect((db.insertAttachment as sinon.SinonStub).secondCall.args).to.deep.equal([{ id: '47' }])

Check failure on line 192 in src/lib/indexer/__tests__/index.test.ts

View workflow job for this annotation

GitHub Actions / Run tests (unit)

Property 'insertAttachment' does not exist on type 'Database'.
})

it('should insert demands and example entries from changeset', async function () {
it('should insert examples and example entries from changeset', async function () {
const db = withInitialLastProcessedBlock({ hash: '1-hash', parent: '0-hash', height: 1 })
const node = withHappyChainNode()
const handleBlock = sinon.stub().resolves({
demands: new Map([
examples: new Map([
['123', { type: 'insert', id: '42' }],
['456', { type: 'insert', id: '43' }],
]),
Expand Down
4 changes: 2 additions & 2 deletions src/lib/indexer/eventProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const DefaultEventProcessors: EventProcessors = {
if (transaction) {
const id = transaction.localId
return {
demands: new Map([
examples: new Map([
[id, { type: 'update', id, state: 'created', latest_token_id: newDemandId, original_token_id: newDemandId }],
]),
}
Expand All @@ -66,7 +66,7 @@ const DefaultEventProcessors: EventProcessors = {

return {
attachments: new Map([[attachment.id, attachment]]),
demands: new Map([[demand.id, demand]]),
examples: new Map([[demand.id, demand]]),
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/services/blockchainWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// import { UUID } from '../../models/strings'
// import { TOKEN_TYPE } from '../../models/tokenType'
// import Database from '../db'
// import { DemandState, Match2State } from '../../models'
// import { examplestate, Match2State } from '../../models'

// const db = new Database()

Expand All @@ -19,7 +19,7 @@
// export const observeTokenId = async (
// tokenType: TOKEN_TYPE,
// localId: UUID,
// state: DemandState | Match2State,
// state: examplestate | Match2State,
// tokenId: number,
// isNewEntity: boolean
// ) => {
Expand Down

0 comments on commit d69bb26

Please sign in to comment.