Compiles properly again

This commit is contained in:
Ethan Frey 2021-04-29 22:37:11 +02:00
parent eaee5e9fa3
commit 78112db01e
3 changed files with 14 additions and 59 deletions

View File

@ -276,27 +276,8 @@ describe("CosmWasmClient", () => {
const result = await client.getContracts(1);
expect(result.length).toBeGreaterThanOrEqual(3);
const [zero, one, two] = result;
expect(zero).toEqual({
address: deployedHackatom.instances[0].address,
codeId: deployedHackatom.codeId,
creator: alice.address0,
admin: undefined,
label: deployedHackatom.instances[0].label,
});
expect(one).toEqual({
address: deployedHackatom.instances[1].address,
codeId: deployedHackatom.codeId,
creator: alice.address0,
admin: undefined,
label: deployedHackatom.instances[1].label,
});
expect(two).toEqual({
address: deployedHackatom.instances[2].address,
codeId: deployedHackatom.codeId,
creator: alice.address0,
admin: alice.address1,
label: deployedHackatom.instances[2].label,
});
const expected = deployedHackatom.instances.map((info) => info.address);
expect(result.slice(0, 3)).toEqual(expected);
});
});

View File

@ -276,24 +276,10 @@ export class CosmWasmClient {
return codeDetails;
}
public async getContracts(codeId: number): Promise<readonly Contract[]> {
const { contractInfos } = await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId);
return (contractInfos || []).map(
({ address, contractInfo }): Contract => {
assert(address, "address missing");
assert(
contractInfo && contractInfo.codeId && contractInfo.creator && contractInfo.label,
"contractInfo missing or incomplete",
);
return {
address: address,
codeId: contractInfo.codeId.toNumber(),
creator: contractInfo.creator,
admin: contractInfo.admin || undefined,
label: contractInfo.label,
};
},
);
public async getContracts(codeId: number): Promise<readonly string[]> {
// TODO: handle pagination - accept as arg or auto-loop
const { contracts } = await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId);
return contracts;
}
/**

View File

@ -190,16 +190,10 @@ describe("WasmExtension", () => {
const transferAmount = coins(707707, "ucosm");
// create new instance and compare before and after
const { contractInfos: existingContractInfos } = await client.wasm.listContractsByCodeId(
hackatomCodeId,
);
assert(existingContractInfos);
for (const { address, contractInfo } of existingContractInfos) {
const { contracts: existingContracts } = await client.wasm.listContractsByCodeId(hackatomCodeId);
assert(existingContracts);
for (const address of existingContracts) {
expect(address).toMatch(bech32AddressMatcher);
assertDefined(contractInfo);
expect(contractInfo.codeId.toNumber()).toEqual(hackatomCodeId);
expect(contractInfo.creator).toMatch(bech32AddressMatcher);
expect(contractInfo.label).toMatch(/^.+$/);
}
const result = await instantiateContract(wallet, hackatomCodeId, beneficiaryAddress, transferAmount);
@ -208,17 +202,11 @@ describe("WasmExtension", () => {
.events.find((event: any) => event.type === "message")
.attributes!.find((attribute: any) => attribute.key === "contract_address").value;
const { contractInfos: newContractInfos } = await client.wasm.listContractsByCodeId(hackatomCodeId);
assert(newContractInfos);
expect(newContractInfos.length).toEqual(existingContractInfos.length + 1);
const newContract = newContractInfos[newContractInfos.length - 1];
expect({ ...newContract.contractInfo }).toEqual({
codeId: Long.fromNumber(hackatomCodeId, true),
creator: alice.address0,
label: "my escrow",
admin: "",
ibcPortId: "",
});
const { contracts: newContracts } = await client.wasm.listContractsByCodeId(hackatomCodeId);
assert(newContracts);
expect(newContracts.length).toEqual(existingContracts.length + 1);
const newContract = newContracts[newContracts.length - 1];
expect(newContract).toMatch(bech32AddressMatcher);
const { contractInfo } = await client.wasm.getContractInfo(myAddress);
assert(contractInfo);