From 97e071e53c4f95e33c08feca4aa345d579379976 Mon Sep 17 00:00:00 2001 From: lenkan Date: Mon, 6 May 2024 15:27:08 +0200 Subject: [PATCH] add unit tests --- test/core/eventing.test.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/core/eventing.test.ts b/test/core/eventing.test.ts index b730a364..b5b697b6 100644 --- a/test/core/eventing.test.ts +++ b/test/core/eventing.test.ts @@ -2,11 +2,12 @@ import libsodium from 'libsodium-wrappers-sumo'; import { Signer } from '../../src/keri/core/signer'; import { strict as assert } from 'assert'; import { MtrDex } from '../../src/keri/core/matter'; -import { incept, messagize } from '../../src/keri/core/eventing'; +import { incept, messagize, rotate } from '../../src/keri/core/eventing'; import { Saider } from '../../src/keri/core/saider'; import { Diger } from '../../src/keri/core/diger'; import { b, d, Ilks } from '../../src/keri/core/core'; import { Siger } from '../../src/keri/core/siger'; +import { randomBytes } from 'crypto'; describe('key event function', () => { it('incept should create inception events', async () => { @@ -190,4 +191,30 @@ describe('key event function', () => { 'BhfNFh5uk-WxvhsL-AABAABB3MJGmBXxSEryNHw3YwZZLRl_6Ws4Me2WFq8PrQ6WlluSOpPqbwXuiG9RvNWZkqeW8A_0VRjokGMVRZ3m-c0I' ); }); + + it('Rotate should create rotation event with hex sequence number', async () => { + await libsodium.ready; + + const signer0 = new Signer({ transferable: true }); + const signer1 = new Signer({ transferable: true }); + const keys0 = [signer0.verfer.qb64]; + const ndigs = [new Diger({}, signer1.verfer.qb64b).qb64]; + const serder = incept({ keys: keys0, ndigs }); + + function createRotation(sn: number) { + return rotate({ + keys: keys0, + pre: serder.ked.i, + ndigs: serder.ked.n, + sn, + isith: 1, + nsith: 1, + }).ked['s']; + } + + assert.equal(createRotation(1), '1'); + assert.equal(createRotation(10), 'a'); + assert.equal(createRotation(14), 'e'); + assert.equal(createRotation(255), 'ff'); + }); });