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

Commit

Permalink
♻️ Resolve conflicts after #7415
Browse files Browse the repository at this point in the history
  • Loading branch information
ishantiw committed Aug 24, 2022
1 parent 7c45966 commit bc42d4c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 42 deletions.
11 changes: 4 additions & 7 deletions framework/src/modules/auth/commands/register_multisignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,22 @@ import {
import { AuthAccountStore } from '../stores/auth_account';
import {
COMMAND_ID_REGISTER_MULTISIGNATURE_GROUP,
COMMAND_NAME_REGISTER_MULTISIGNATURE_GROUP,
MAX_NUMBER_OF_SIGNATURES,
MESSAGE_TAG_MULTISIG_REG,
TYPE_ID_INVALID_SIGNATURE_ERROR,
TYPE_ID_MULTISIGNATURE_GROUP_REGISTERED,
} from '../constants';
import {
authAccountSchema,
invalidSigDataSchema,
multisigRegDataSchema,
multisigRegMsgSchema,
registerMultisignatureParamsSchema,
} from '../schemas';
import { AuthAccount, RegisterMultisignatureParams } from '../types';
import { RegisterMultisignatureParams } from '../types';
import { getIDAsKeyForStore } from '../utils';

export class RegisterMultisignatureCommand extends BaseCommand {
public id = getIDAsKeyForStore(COMMAND_ID_REGISTER_MULTISIGNATURE_GROUP);
public name = COMMAND_NAME_REGISTER_MULTISIGNATURE_GROUP;
public schema = registerMultisignatureParamsSchema;

// eslint-disable-next-line @typescript-eslint/require-await
Expand Down Expand Up @@ -119,12 +116,12 @@ export class RegisterMultisignatureCommand extends BaseCommand {
};
}

// Check if the length of mandatory, optional and sender keys matches the length of signatures
// Check if the length of mandatory, optional keys is equal to length of signatures
if (mandatoryKeys.length + optionalKeys.length !== signatures.length) {
return {
status: VerifyStatus.FAIL,
error: new Error(
'The number of mandatory, optional and sender keys should match the number of signatures',
'The number of mandatory and optional keys should match the number of signatures',
),
};
}
Expand Down Expand Up @@ -211,7 +208,7 @@ export class RegisterMultisignatureCommand extends BaseCommand {
senderAccount.optionalKeys = params.optionalKeys;
senderAccount.numberOfSignatures = params.numberOfSignatures;

await authSubstore.setWithSchema(transaction.senderAddress, senderAccount, authAccountSchema);
await authSubstore.set(context, transaction.senderAddress, senderAccount);

const registerMultiSigEventData = codec.encode(multisigRegDataSchema, {
numberOfSignatures: params.numberOfSignatures,
Expand Down
2 changes: 2 additions & 0 deletions framework/src/modules/auth/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*
* Removal or modification of this copyright notice is prohibited.
*/
import { utils } from '@liskhq/lisk-cryptography';

export const COMMAND_NAME_REGISTER_MULTISIGNATURE_GROUP = 'registerMultisignatureGroup';
export const MAX_NUMBER_OF_SIGNATURES = 64;

Expand Down
28 changes: 12 additions & 16 deletions framework/src/modules/auth/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import {
VerificationResult,
} from '../../state_machine';
import { AuthAPI } from './api';
import { RegisterMultisignatureGroupCommand } from './commands/register_multisignature';
import { MAX_NUMBER_OF_SIGNATURES } from './constants';
import { AuthEndpoint } from './endpoint';
import { configSchema, genesisAuthStoreSchema } from './schemas';
import { GenesisAuthStore, ImmutableStoreCallback } from './types';
import { verifyNonce, verifySignatures } from './utils';
import { AuthAccount, authAccountSchema, AuthAccountStore } from './stores/auth_account';
import { RegisterMultisignatureCommand } from './commands/register_multisignature';

export class AuthModule extends BaseModule {
public api = new AuthAPI(this.stores, this.events);
public endpoint = new AuthEndpoint(this.name, this.stores, this.offchainStores);
public configSchema = configSchema;
public commands = [new RegisterMultisignatureGroupCommand(this.stores, this.events)];
public commands = [new RegisterMultisignatureCommand(this.stores, this.events)];

public constructor() {
super();
Expand Down Expand Up @@ -184,33 +184,29 @@ export class AuthModule extends BaseModule {

const senderAccount = await store.get(context, transaction.senderAddress);
senderAccount.nonce += BigInt(1);
await authStore.setWithSchema(
address,
{
nonce: senderAccount.nonce,
numberOfSignatures: senderAccount.numberOfSignatures,
mandatoryKeys: senderAccount.mandatoryKeys,
optionalKeys: senderAccount.optionalKeys,
},
authAccountSchema,
);
await store.set(context, transaction.senderAddress, {
nonce: senderAccount.nonce,
numberOfSignatures: senderAccount.numberOfSignatures,
mandatoryKeys: senderAccount.mandatoryKeys,
optionalKeys: senderAccount.optionalKeys,
});
}

// TODO: Change it to private once implemented
protected async _isMultisignatureAccount(
getStore: ImmutableStoreCallback,
address: Buffer,
): Promise<boolean> {
const authSubstore = getStore(this.id, STORE_PREFIX_AUTH);
const authSubstore = this.stores.get(AuthAccountStore);
try {
const authAccount = await authSubstore.getWithSchema<AuthAccount>(address, authAccountSchema);
const authAccount = await authSubstore.get({ getStore }, address);

return authAccount.numberOfSignatures !== 0;
} catch (error) {
if (!(error instanceof NotFoundError)) {
throw error;
}

await store.set(context, transaction.senderAddress, senderAccount);
return false;
}
}
}
3 changes: 2 additions & 1 deletion framework/src/modules/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
*/

import { ImmutableSubStore } from '../../state_machine';
import { AuthAccount } from './stores/auth_account';

export type ImmutableStoreCallback = (moduleID: Buffer, storePrefix: number) => ImmutableSubStore;
export type ImmutableStoreCallback = (moduleID: Buffer, storePrefix: Buffer) => ImmutableSubStore;
export interface Keys {
numberOfSignatures: number;
mandatoryKeys: Buffer[];
Expand Down
30 changes: 12 additions & 18 deletions framework/test/unit/modules/auth/register_multisignature.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@ import * as fixtures from './fixtures.json';
import * as testing from '../../../../src/testing';
import { RegisterMultisignatureCommand } from '../../../../src/modules/auth/commands/register_multisignature';
import {
MODULE_ID_AUTH_BUFFER,
STORE_PREFIX_AUTH,
TYPE_ID_INVALID_SIGNATURE_ERROR,
TYPE_ID_MULTISIGNATURE_GROUP_REGISTERED,
} from '../../../../src/modules/auth/constants';
import {
authAccountSchema,
invalidSigDataSchema,
multisigRegDataSchema,
registerMultisignatureParamsSchema,
} from '../../../../src/modules/auth/schemas';
import { AuthAccount, RegisterMultisignatureParams } from '../../../../src/modules/auth/types';
import { RegisterMultisignatureParams } from '../../../../src/modules/auth/types';
import { VerifyStatus } from '../../../../src/state_machine';
import { PrefixedStateReadWriter } from '../../../../src/state_machine/prefixed_state_read_writer';
import { InMemoryPrefixedStateDB } from '../../../../src/testing/in_memory_prefixed_state';
import { AuthModule } from '../../../../src/modules/auth';
import { AuthAccountStore } from '../../../../src/modules/auth/stores/auth_account';

describe('Register Multisignature command', () => {
let registerMultisignatureCommand: RegisterMultisignatureGroupCommand;
let registerMultisignatureCommand: RegisterMultisignatureCommand;
let stateStore: PrefixedStateReadWriter;
let authStore: AuthAccountStore;
let transaction: Transaction;
Expand All @@ -49,7 +46,7 @@ describe('Register Multisignature command', () => {
const networkIdentifier = Buffer.from(defaultTestCase.input.networkIdentifier, 'hex');

beforeEach(() => {
registerMultisignatureCommand = new RegisterMultisignatureGroupCommand(
registerMultisignatureCommand = new RegisterMultisignatureCommand(
authModule.stores,
authModule.events,
);
Expand Down Expand Up @@ -461,7 +458,7 @@ describe('Register Multisignature command', () => {
const updatedData = await updatedStore.get(context, transaction.senderAddress);
expect(updatedData.mandatoryKeys).toEqual(decodedParams.mandatoryKeys);
expect(eventQueueMock.add).toHaveBeenCalledWith(
'registerMultisignatureGroup',
'registerMultisignature',
TYPE_ID_MULTISIGNATURE_GROUP_REGISTERED,
registerMultiSigEventData,
[transaction.senderAddress],
Expand All @@ -486,16 +483,6 @@ describe('Register Multisignature command', () => {
...multiSignatureTx.toObject(),
params: paramsBytes,
});
await authStore.setWithSchema(
transaction.senderAddress,
{
optionalKeys: [],
mandatoryKeys: [],
numberOfSignatures: 0,
nonce: BigInt(0),
},
authAccountSchema,
);

const context = testing
.createTransactionContext({
Expand All @@ -507,6 +494,13 @@ describe('Register Multisignature command', () => {
registerMultisignatureParamsSchema,
);

await authStore.set(context, transaction.senderAddress, {
optionalKeys: [],
mandatoryKeys: [],
numberOfSignatures: 0,
nonce: BigInt(0),
});

context.eventQueue = eventQueueMock;

const invalidSignatureEventData = codec.encode(invalidSigDataSchema, {
Expand All @@ -521,7 +515,7 @@ describe('Register Multisignature command', () => {
);

expect(eventQueueMock.add).toBeCalledWith(
'registerMultisignatureGroup',
'registerMultisignature',
TYPE_ID_INVALID_SIGNATURE_ERROR,
invalidSignatureEventData,
[invalidTransaction.senderAddress],
Expand Down

0 comments on commit bc42d4c

Please sign in to comment.