Skip to content

Commit

Permalink
Merge pull request #311 from terra-money/fix/wasm-api
Browse files Browse the repository at this point in the history
fix wasm api to query code info
  • Loading branch information
Vritra4 committed Jul 11, 2022
2 parents 20e884b + 112e7fd commit 5f868c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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
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

0 comments on commit 5f868c1

Please sign in to comment.