-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add MsgUpdateNamespace file and spec file
- Loading branch information
1 parent
0e16f25
commit 3de8410
Showing
2 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/sdk-ts/src/core/modules/permissions/msgs/MsgUpdateNamespace.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |
125 changes: 125 additions & 0 deletions
125
packages/sdk-ts/src/core/modules/permissions/msgs/MsgUpdateNamespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |