Skip to content

Commit

Permalink
feat: add MsgUpdateNamespace file and spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan-LukeKlopper committed Aug 6, 2024
1 parent 0e16f25 commit 3de8410
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import snakecaseKeys from 'snakecase-keys';
import MsgUpdateNamespace from './MsgUpdateNamespace';
import { mockFactory } from '@injectivelabs/test-utils';

const params: MsgUpdateNamespace['params'] = {
sender: mockFactory.injectiveAddress,
namespaceDenom: 'namespace_denom',
wasmHook: 'wasmHookAddress',
mintsPaused: true,
sendsPaused: false,
burnsPaused: true,
};

const protoType = '/injective.permissions.v1beta1.MsgUpdateNamespace';
const protoTypeShort = 'permissions/MsgUpdateNamespace';
const protoParams = {
sender: params.sender,
namespaceDenom: params.namespaceDenom,
wasmHook: {
newValue: params.wasmHook,
},
mintsPaused: {
newValue: params.mintsPaused,
},
sendsPaused: {
newValue: params.sendsPaused,
},
burnsPaused: {
newValue: params.burnsPaused,
},
};

const protoParamsAmino = snakecaseKeys(protoParams);

const message = MsgUpdateNamespace.fromJSON(params);

describe('MsgUpdateNamespace', () => {
it('generates proper proto', () => {
const proto = message.toProto();

expect(proto).toStrictEqual(protoParams);
});

it('generates proper data', () => {
const data = message.toData();

expect(data).toStrictEqual({
'@type': protoType,
...protoParams,
});
});

it('generates proper amino', () => {
const amino = message.toAmino();

expect(amino).toStrictEqual({
type: protoTypeShort,
value: protoParamsAmino,
});
});

it('generates proper web3', () => {
const web3 = message.toWeb3();

expect(web3).toStrictEqual({
'@type': protoType,
...protoParamsAmino,
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { MsgBase } from '../../MsgBase';
import snakecaseKeys from 'snakecase-keys';

// future imports

// import {
// InjectivePermissionsV1Beta1Tx
// } from '@injectivelabs/care-proto-ts'

export declare namespace MsgUpdateNamespace {
export interface Params {
sender: string;
namespaceDenom: string;
wasmHook: string;
mintsPaused: boolean;
sendsPaused: boolean;
burnsPaused: boolean;
}

// Temporary Proto declaration
export type Proto = {
sender: string;
namespaceDenom: string;
wasmHook: {
newValue: string;
};
mintsPaused: {
newValue: boolean;
};
sendsPaused: {
newValue: boolean;
};
burnsPaused: {
newValue: boolean;
};
};

// future Proto declaration
// export type Proto = InjectivePermissionsV1Beta1Tx.MsgUpdateNamespace
}

/**
* @category Messages
*/
export default class MsgUpdateNamespace extends MsgBase<
MsgUpdateNamespace.Params,
MsgUpdateNamespace.Proto
> {
static fromJSON(params: MsgUpdateNamespace.Params): MsgUpdateNamespace {
return new MsgUpdateNamespace(params);
}

public toProto() {
const { params } = this;

const message = {
sender: params.sender,
namespaceDenom: params.namespaceDenom,
wasmHook: {
newValue: params.wasmHook,
},
mintsPaused: {
newValue: params.mintsPaused,
},
sendsPaused: {
newValue: params.sendsPaused,
},
burnsPaused: {
newValue: params.burnsPaused,
},
};

return message;
}

public toData() {
const proto = this.toProto();

return {
'@type': '/injective.permissions.v1beta1.MsgUpdateNamespace',
...proto,
};
}

public toAmino() {
const proto = this.toProto();
const message = {
...snakecaseKeys(proto),
};

return {
type: 'permissions/MsgUpdateNamespace',
value: message,
};
}

public toWeb3() {
const amino = this.toAmino();
const { value } = amino;

return {
'@type': '/injective.permissions.v1beta1.MsgUpdateNamespace',
...value,
};
}

public toDirectSign() {
const proto = this.toProto();

return {
type: '/injective.permissions.v1beta1.MsgUpdateNamespace',
message: proto,
};
}

public toBinary(): Uint8Array {
// Placeholder for binary encoding
return new Uint8Array();

//// Expected binary encoding
// return InjectivePermissionsV1Beta1Tx.MsgUpdateNamespace.encode()
// this.toProto(),
// ).finish()
}
}

0 comments on commit 3de8410

Please sign in to comment.