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

Commit

Permalink
Align genesis schema and processing with lip auth (#8846)
Browse files Browse the repository at this point in the history
* Renaming entities of genesisAuthStoreSchema

* Update framework/src/modules/auth/module.ts

---------

Co-authored-by: !shan <ishantiw.quasar@gmail.com>
  • Loading branch information
Phanco and ishantiw authored Aug 15, 2023
1 parent 0204df1 commit b07bdbb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
14 changes: 7 additions & 7 deletions framework/src/modules/auth/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ export class AuthModule extends BaseModule {
const genesisStore = codec.decode<GenesisAuthStore>(genesisAuthStoreSchema, assetBytes);
const store = this.stores.get(AuthAccountStore);
const keys = [];
for (const { storeKey, storeValue } of genesisStore.authDataSubstore) {
if (storeKey.length !== ADDRESS_LENGTH) {
for (const { address, authAccount } of genesisStore.authDataSubstore) {
if (address.length !== ADDRESS_LENGTH) {
throw new Error('Invalid store key length for auth module.');
}
keys.push(storeKey);
keys.push(address);

validator.validate(authAccountSchema, storeValue);
validator.validate(authAccountSchema, authAccount);

const { mandatoryKeys, optionalKeys, numberOfSignatures } = storeValue;
const { mandatoryKeys, optionalKeys, numberOfSignatures } = authAccount;

if (!objectUtils.isBufferArrayOrdered(mandatoryKeys)) {
throw new Error(
Expand Down Expand Up @@ -165,10 +165,10 @@ export class AuthModule extends BaseModule {
throw new Error('The numberOfSignatures is smaller than the count of Mandatory keys.');
}

await store.set(context, storeKey, storeValue);
await store.set(context, address, authAccount);
}
if (!objectUtils.bufferArrayUniqueItems(keys)) {
throw new Error('Duplicate store key for auth module.');
throw new Error('Duplicate address in the for auth module.');
}
}

Expand Down
10 changes: 7 additions & 3 deletions framework/src/modules/auth/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ export const genesisAuthStoreSchema = {
fieldNumber: 1,
items: {
type: 'object',
required: ['storeKey', 'storeValue'],
required: ['address', 'authAccount'],
properties: {
storeKey: {
address: {
dataType: 'bytes',
fieldNumber: 1,
},
storeValue: {
authAccount: {
type: 'object',
fieldNumber: 2,
required: ['nonce', 'numberOfSignatures', 'mandatoryKeys', 'optionalKeys'],
Expand All @@ -196,13 +196,17 @@ export const genesisAuthStoreSchema = {
fieldNumber: 3,
items: {
dataType: 'bytes',
minLength: ED25519_PUBLIC_KEY_LENGTH,
maxLength: ED25519_PUBLIC_KEY_LENGTH,
},
},
optionalKeys: {
type: 'array',
fieldNumber: 4,
items: {
dataType: 'bytes',
minLength: ED25519_PUBLIC_KEY_LENGTH,
maxLength: ED25519_PUBLIC_KEY_LENGTH,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions framework/src/modules/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export interface SortedMultisignatureGroup {

export interface GenesisAuthStore {
authDataSubstore: {
storeKey: Buffer;
storeValue: AuthAccount;
address: Buffer;
authAccount: AuthAccount;
}[];
}

Expand Down
42 changes: 21 additions & 21 deletions framework/test/unit/modules/auth/module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ describe('AuthModule', () => {
const validAsset = {
authDataSubstore: [
{
storeKey: address,
storeValue: {
address,
authAccount: {
numberOfSignatures: 0,
mandatoryKeys: [],
optionalKeys: [],
nonce: BigInt(23),
},
},
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 3,
mandatoryKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) =>
a.compare(b),
Expand All @@ -128,8 +128,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(8),
storeValue: {
address: utils.getRandomBytes(8),
authAccount: {
numberOfSignatures: 0,
mandatoryKeys: [],
optionalKeys: [],
Expand All @@ -144,8 +144,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 3,
mandatoryKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) =>
b.compare(a),
Expand All @@ -162,8 +162,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 2,
mandatoryKeys: [publicKey, publicKey],
optionalKeys: [],
Expand All @@ -178,8 +178,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 3,
mandatoryKeys: [],
optionalKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) =>
Expand All @@ -196,8 +196,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 2,
mandatoryKeys: [],
optionalKeys: [publicKey, publicKey],
Expand All @@ -212,8 +212,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 36,
mandatoryKeys: Array.from({ length: 33 }, () => utils.getRandomBytes(32)).sort(
(a, b) => b.compare(a),
Expand All @@ -232,8 +232,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 3,
mandatoryKeys: [],
optionalKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) =>
Expand All @@ -250,8 +250,8 @@ describe('AuthModule', () => {
{
authDataSubstore: [
{
storeKey: utils.getRandomBytes(ADDRESS_LENGTH),
storeValue: {
address: utils.getRandomBytes(ADDRESS_LENGTH),
authAccount: {
numberOfSignatures: 1,
mandatoryKeys: [utils.getRandomBytes(32), utils.getRandomBytes(32)].sort((a, b) =>
b.compare(a),
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('AuthModule', () => {
await expect(authModule.initGenesisState(context)).toResolve();
const authStore = authModule.stores.get(AuthAccountStore);
for (const data of validAsset.authDataSubstore) {
await expect(authStore.has(context, data.storeKey)).resolves.toBeTrue();
await expect(authStore.has(context, data.address)).resolves.toBeTrue();
}
});

Expand Down

0 comments on commit b07bdbb

Please sign in to comment.