Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix defaultQuorum typo #472

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function toMap (nodes) {

function defaultQuorum (man) {
if (typeof man.quorum === 'number') return man.quorum
if (!man.signers || man.signers.length) return 0
if (!man.signers || !man.signers.length) return 0
return (man.signers.length >> 1) + 1
}

Expand Down
67 changes: 67 additions & 0 deletions test/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,73 @@ test('multisig - append/truncate before prologue', async function (t) {
await t.exception(core.truncate(1, { signature: partialMultisig }))
})

test('create verifier - default quorum', async function (t) {
const keyPair = crypto.keyPair()
const keyPair2 = crypto.keyPair()

const namespace = b4a.alloc(32, 2)

const manifest = {
version: 0,
signers: [{
signature: 'ed25519',
namespace,
publicKey: keyPair.publicKey
}]
}

const manifestv1 = {
version: 1,
signers: [{
signature: 'ed25519',
namespace,
publicKey: keyPair.publicKey
}]
}

const manifestMultiple = {
version: 0,
signers: [
{
signature: 'ed25519',
namespace,
publicKey: keyPair.publicKey
},
{
signature: 'ed25519',
namespace,
publicKey: keyPair2.publicKey
}
]
}

const manifestMultiplev1 = {
version: 1,
signers: [
{
signature: 'ed25519',
namespace,
publicKey: keyPair.publicKey
},
{
signature: 'ed25519',
namespace,
publicKey: keyPair2.publicKey
}
]
}

const single = new Verifier(manifest)
const singlev1 = new Verifier(manifestv1)
const multiple = new Verifier(manifestMultiple)
const multiplev1 = new Verifier(manifestMultiplev1)

t.is(single.quorum, 1)
t.is(singlev1.quorum, 1)
t.is(multiple.quorum, 2)
t.is(multiplev1.quorum, 2)
})

function createMultiManifest (signers, prologue = null) {
return {
hash: 'blake2b',
Expand Down