Skip to content

Commit

Permalink
L3-195: offchain/onchain tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
n3op2 committed Oct 9, 2023
1 parent dfd7977 commit 331a7e9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/indexer/eventProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ const DefaultEventProcessors: EventProcessors = {
]),
}
},
/* why this is here? should it not be part of l3-195?
'rematch2-acceptFinal': (version, _transaction, _sender, inputs, outputs) => {
if (version !== 1) throw new Error(`Incompatible version ${version} for rematch2-acceptFinal process`)
Expand Down Expand Up @@ -338,6 +339,7 @@ const DefaultEventProcessors: EventProcessors = {
]),
}
},
*/

// eslint-disable-next-line @typescript-eslint/no-unused-vars
'match2-reject': (version, _transaction, _sender, inputs, _outputs) => {
Expand Down
44 changes: 44 additions & 0 deletions test/integration/onchain/match2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,50 @@ describe('on-chain', function () {
expect(rematch2.latestTokenId).to.equal(lastTokenId + 4)
})

it.only('accepts a rematch2 proposal', async () => {
const proposal = await post(context.app, `/v1/match2/${ids.match2}/proposal`, {})
await pollTransactionState(db, proposal.body.id, 'finalised')
const resAcceptA = await post(context.app, `/v1/match2/${ids.match2}/accept`, {})
await pollTransactionState(db, resAcceptA.body.id, 'finalised')
const resAcceptFinal = await post(context.app, `/v1/match2/${ids.match2}/accept`, {})
await pollTransactionState(db, resAcceptFinal.body.id, 'finalised')

const lastTokenId = await node.getLastTokenId()
const reMatch = await post(context.app, '/v1/match2', {
demandA: ids.demandA,
demandB: ids.newDemandB,
replaces: ids.match2,
})
ids.rematch2 = reMatch.body['id'] as string

const resProposal = await post(context.app, `/v1/match2/${ids.rematch2}/proposal`, {})
console.log({ resProposal, reMatch })

Check failure on line 217 in test/integration/onchain/match2.test.ts

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected console statement
await pollTransactionState(db, resProposal.body.id, 'finalised')

// output
const [match2]: Match2Row[] = await db.getMatch2(ids.match2)
const [demandA]: DemandRow[] = await db.getDemand(ids.demandA)
const [demandB]: DemandRow[] = await db.getDemand(match2.demandB)
const [newDemandB]: DemandRow[] = await db.getDemand(ids.newDemandB)
const [rematch2]: Match2Row[] = await db.getMatch2(ids.rematch2)

expect(demandA.state).to.equal('allocated')
expect(demandA.latestTokenId).to.equal(lastTokenId + 1)
expect(demandA.originalTokenId).to.equal(ids.originalDemandA)

expect(demandB.state).to.equal('allocated')
expect(demandB.latestTokenId).to.equal(lastTokenId + 2)

expect(match2.state).to.equal('cancelled')
expect(match2.latestTokenId).to.equal(lastTokenId + 3)

expect(newDemandB.state).to.equal('allocated')
expect(newDemandB.latestTokenId).to.equal(lastTokenId + 4)

expect(rematch2.state).to.equal('acceptedA')
expect(rematch2.latestTokenId).to.equal(lastTokenId + 5)
})

describe('if multiple accepts have been submitted', () => {
it('handles error and marks only one transaction finalised and others as failed', async () => {
const proposal = await post(context.app, `/v1/match2/${ids.match2}/proposal`, {})
Expand Down

0 comments on commit 331a7e9

Please sign in to comment.