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 wasm api to query code info #311

Merged
merged 2 commits into from
Jul 11, 2022
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
26 changes: 26 additions & 0 deletions src/client/lcd/api/WasmAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,30 @@ describe('WasmAPI', () => {
});
}
});

it('code_info', async () => {
// only classic network has param query
await expect(wasm.codeInfo(1)).resolves.toMatchObject({
code_id: 1,
creator: 'terra1zpglp37eg85mtwa54ymgj0nzqe37awhsv42yxj',
code_hash:
'325A94095F5D98B816AB5192C7771B43D9E45800846B5F2CC96B92E5F3492D45',
instantiate_permission: {
permission: 3,
address: '',
},
});
});

/* access denied
it('all_codes', async () => {
// only classic network has param query
const [codes, _] = await wasm.allCodes();
codes.forEach(code => {
expect(code.code_id).toBeDefined();
expect(code.code_hash).toBeDefined();
expect(code.creator).toBeDefined();
});
});
*/
});
8 changes: 4 additions & 4 deletions src/client/lcd/api/WasmAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AccessConfig } from '../../../core/wasm';

export interface CodeInfo {
code_id: number;
code_hash: string;
code_hash: string; // TODO: rename it to data_hash when bumping to v4
Vritra4 marked this conversation as resolved.
Show resolved Hide resolved
creator: AccAddress;
instantiate_config?: AccessConfig;
}
Expand All @@ -21,7 +21,7 @@ export namespace CodeInfo {
}
export interface DataV2 {
code_id: string;
code_hash: string;
data_hash: string;
creator: AccAddress;
instantiate_permission?: AccessConfig.Data;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ export class WasmAPI extends BaseAPI {
.get<{ code_info: CodeInfo.DataV2 }>(endpoint, params)
.then(({ code_info: d }) => ({
code_id: +d.code_id,
code_hash: d.code_hash,
code_hash: d.data_hash,
creator: d.creator,
instantiate_permission: d.instantiate_permission
? AccessConfig.fromData(d.instantiate_permission)
Expand Down Expand Up @@ -320,7 +320,7 @@ export class WasmAPI extends BaseAPI {
d.codeInfos.map(codeInfo => {
return {
code_id: +codeInfo.code_id,
code_hash: codeInfo.code_hash,
code_hash: codeInfo.data_hash,
creator: codeInfo.creator,
instantiate_permission: codeInfo.instantiate_permission
? AccessConfig.fromData(codeInfo.instantiate_permission)
Expand Down
2 changes: 2 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export * from './staking/Validator';
export * from './treasury/PolicyConstraints';

// WASM
export * from './wasm';
export * from './wasm/msgs';
export * from './wasm/proposals';

// IBC
export * from './ibc/msgs/channel';
Expand Down