-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SPV
listAnchors
, listAnchorsPending
, listAnchorAuths
and `s…
…etLastHeight` rpc (#618) * added listanchors update desc * added listanchorspending * added listanchorauths typo * added setlastheight * pr changes fix * jellyfish-testing supports multinodes (#621) * jellyfish supports multinode added jellyfish-testing misc * missing param on doc * refactor testing in group apply new TestingGroup to test fix syntax err * pr changes * refine the optional input mnkeys logic * added configurable container * refactor testing.ts with default and used exec Co-authored-by: Fuxing Loh <[email protected]> * refactor to use tgroup * fix path * added generateanchorauth * refine setlastheight test * refactor: testinganchor to testinggroupanchor * add desc for generateanchorauths * fix fix * temp ignore test * remove redundent default params * remove extra br * fix Co-authored-by: Fuxing Loh <[email protected]>
- Loading branch information
1 parent
9f1ac6b
commit ee7767c
Showing
12 changed files
with
878 additions
and
157 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
79 changes: 79 additions & 0 deletions
79
packages/jellyfish-api-core/__tests__/category/spv/listAnchorAuths.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,79 @@ | ||
import { TestingGroup } from '@defichain/jellyfish-testing' | ||
import { GenesisKeys } from '@defichain/testcontainers' | ||
|
||
describe('Spv', () => { | ||
const tGroup = TestingGroup.create(3) | ||
|
||
beforeAll(async () => { | ||
await tGroup.start() | ||
await setup() | ||
}) | ||
|
||
afterAll(async () => { | ||
await tGroup.stop() | ||
}) | ||
|
||
async function setMockTime (offsetHour: number): Promise<void> { | ||
await tGroup.exec(async testing => { | ||
await testing.misc.offsetTimeHourly(offsetHour) | ||
}) | ||
} | ||
|
||
async function setup (): Promise<void> { | ||
const auths = await tGroup.get(0).container.call('spv_listanchorauths') | ||
expect(auths.length).toStrictEqual(0) | ||
|
||
// time travel back 12 hours ago | ||
const initOffsetHour = -12 | ||
await setMockTime(initOffsetHour) | ||
|
||
// 15 as anchor frequency | ||
for (let i = 0; i < 15; i += 1) { | ||
const { container } = tGroup.get(i % tGroup.length()) | ||
await container.generate(1) | ||
await tGroup.waitForSync() | ||
} | ||
|
||
const blockCount = await tGroup.get(0).container.getBlockCount() | ||
expect(blockCount).toStrictEqual(15) | ||
|
||
// check the auth and confirm anchor mn teams | ||
await tGroup.get(0).container.waitForAnchorTeams(tGroup.length()) | ||
|
||
// assertion for team | ||
for (let i = 0; i < tGroup.length(); i += 1) { | ||
const { container } = tGroup.get(i % tGroup.length()) | ||
const team = await container.call('getanchorteams') | ||
expect(team.auth.length).toStrictEqual(tGroup.length()) | ||
expect(team.confirm.length).toStrictEqual(tGroup.length()) | ||
expect(team.auth.includes(GenesisKeys[0].operator.address)) | ||
expect(team.auth.includes(GenesisKeys[1].operator.address)) | ||
expect(team.auth.includes(GenesisKeys[2].operator.address)) | ||
expect(team.confirm.includes(GenesisKeys[0].operator.address)) | ||
expect(team.confirm.includes(GenesisKeys[1].operator.address)) | ||
expect(team.confirm.includes(GenesisKeys[2].operator.address)) | ||
} | ||
|
||
// generate 2 anchor auths | ||
await tGroup.anchor.generateAnchorAuths(2, initOffsetHour) | ||
|
||
await tGroup.get(0).container.waitForAnchorAuths(tGroup.length()) | ||
} | ||
|
||
it('should listAnchorAuths', async () => { | ||
for (let i = 0; i < 2; i += 1) { | ||
const auths = await tGroup.get(0).rpc.spv.listAnchorAuths() | ||
expect(auths.length).toStrictEqual(2) | ||
expect(typeof auths[i].previousAnchor).toStrictEqual('string') | ||
expect(typeof auths[i].blockHeight).toStrictEqual('number') | ||
expect(typeof auths[i].blockHash).toStrictEqual('string') | ||
expect(typeof auths[i].creationHeight).toStrictEqual('number') | ||
expect(typeof auths[i].signers).toStrictEqual('number') | ||
expect(auths[i].signers).toStrictEqual(tGroup.length()) | ||
expect(auths[i].signees?.length).toStrictEqual(tGroup.length()) | ||
expect(auths[i].signees?.includes(GenesisKeys[0].operator.address)) | ||
expect(auths[i].signees?.includes(GenesisKeys[1].operator.address)) | ||
expect(auths[i].signees?.includes(GenesisKeys[2].operator.address)) | ||
} | ||
}) | ||
}) |
Oops, something went wrong.