mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Make many test independent of ERC20_ENABLED
This commit is contained in:
parent
60bed447aa
commit
4af419b365
@ -19,10 +19,9 @@ import { SigningCosmWasmClient } from "./signingcosmwasmclient";
|
||||
import cosmoshub from "./testdata/cosmoshub.json";
|
||||
import {
|
||||
alice,
|
||||
deployedErc20,
|
||||
deployedHackatom,
|
||||
getHackatom,
|
||||
makeRandomAddress,
|
||||
pendingWithoutErc20,
|
||||
pendingWithoutWasmd,
|
||||
tendermintIdMatcher,
|
||||
unused,
|
||||
@ -255,16 +254,15 @@ describe("CosmWasmClient", () => {
|
||||
describe("getCodes", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead
|
||||
const client = new CosmWasmClient(wasmd.endpoint);
|
||||
const result = await client.getCodes();
|
||||
expect(result.length).toBeGreaterThanOrEqual(1);
|
||||
const [first] = result;
|
||||
expect(first).toEqual({
|
||||
id: deployedErc20.codeId,
|
||||
source: deployedErc20.source,
|
||||
builder: deployedErc20.builder,
|
||||
checksum: deployedErc20.checksum,
|
||||
id: deployedHackatom.codeId,
|
||||
source: deployedHackatom.source,
|
||||
builder: deployedHackatom.builder,
|
||||
checksum: deployedHackatom.checksum,
|
||||
creator: alice.address0,
|
||||
});
|
||||
});
|
||||
@ -273,15 +271,14 @@ describe("CosmWasmClient", () => {
|
||||
describe("getCodeDetails", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead
|
||||
const client = new CosmWasmClient(wasmd.endpoint);
|
||||
const result = await client.getCodeDetails(1);
|
||||
|
||||
const expectedInfo: Code = {
|
||||
id: deployedErc20.codeId,
|
||||
source: deployedErc20.source,
|
||||
builder: deployedErc20.builder,
|
||||
checksum: deployedErc20.checksum,
|
||||
id: deployedHackatom.codeId,
|
||||
source: deployedHackatom.source,
|
||||
builder: deployedHackatom.builder,
|
||||
checksum: deployedHackatom.checksum,
|
||||
creator: alice.address0,
|
||||
};
|
||||
|
||||
@ -293,13 +290,12 @@ describe("CosmWasmClient", () => {
|
||||
|
||||
it("caches downloads", async () => {
|
||||
pendingWithoutWasmd();
|
||||
pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead
|
||||
const client = new CosmWasmClient(wasmd.endpoint);
|
||||
const openedClient = (client as unknown) as PrivateCosmWasmClient;
|
||||
const getCodeSpy = spyOn(openedClient.lcdClient.wasm, "getCode").and.callThrough();
|
||||
|
||||
const result1 = await client.getCodeDetails(deployedErc20.codeId); // from network
|
||||
const result2 = await client.getCodeDetails(deployedErc20.codeId); // from cache
|
||||
const result1 = await client.getCodeDetails(deployedHackatom.codeId); // from network
|
||||
const result2 = await client.getCodeDetails(deployedHackatom.codeId); // from cache
|
||||
expect(result2).toEqual(result1);
|
||||
|
||||
expect(getCodeSpy).toHaveBeenCalledTimes(1);
|
||||
@ -309,31 +305,30 @@ describe("CosmWasmClient", () => {
|
||||
describe("getContracts", () => {
|
||||
it("works", async () => {
|
||||
pendingWithoutWasmd();
|
||||
pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead
|
||||
const client = new CosmWasmClient(wasmd.endpoint);
|
||||
const result = await client.getContracts(1);
|
||||
expect(result.length).toBeGreaterThanOrEqual(3);
|
||||
const [hash, isa, jade] = result;
|
||||
expect(hash).toEqual({
|
||||
address: "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5",
|
||||
const [zero, one, two] = result;
|
||||
expect(zero).toEqual({
|
||||
address: deployedHackatom.instances[0].address,
|
||||
codeId: 1,
|
||||
creator: alice.address0,
|
||||
admin: undefined,
|
||||
label: "HASH",
|
||||
label: deployedHackatom.instances[0].label,
|
||||
});
|
||||
expect(isa).toEqual({
|
||||
address: "cosmos1hqrdl6wstt8qzshwc6mrumpjk9338k0lr4dqxd",
|
||||
expect(one).toEqual({
|
||||
address: deployedHackatom.instances[1].address,
|
||||
codeId: 1,
|
||||
creator: alice.address0,
|
||||
admin: undefined,
|
||||
label: "ISA",
|
||||
label: deployedHackatom.instances[1].label,
|
||||
});
|
||||
expect(jade).toEqual({
|
||||
address: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c",
|
||||
expect(two).toEqual({
|
||||
address: deployedHackatom.instances[2].address,
|
||||
codeId: 1,
|
||||
creator: alice.address0,
|
||||
admin: alice.address1,
|
||||
label: "JADE",
|
||||
label: deployedHackatom.instances[2].label,
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -341,27 +336,27 @@ describe("CosmWasmClient", () => {
|
||||
describe("getContract", () => {
|
||||
it("works for instance without admin", async () => {
|
||||
pendingWithoutWasmd();
|
||||
pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead
|
||||
const client = new CosmWasmClient(wasmd.endpoint);
|
||||
const hash = await client.getContract("cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5");
|
||||
expect(hash).toEqual({
|
||||
address: "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5",
|
||||
codeId: 1,
|
||||
const zero = await client.getContract(deployedHackatom.instances[0].address);
|
||||
expect(zero).toEqual({
|
||||
address: deployedHackatom.instances[0].address,
|
||||
codeId: deployedHackatom.codeId,
|
||||
creator: alice.address0,
|
||||
label: "HASH",
|
||||
label: deployedHackatom.instances[0].label,
|
||||
admin: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("works for instance with admin", async () => {
|
||||
pendingWithoutWasmd();
|
||||
pendingWithoutErc20(); // TODO: Adapt test to use hackatom instead
|
||||
const client = new CosmWasmClient(wasmd.endpoint);
|
||||
const jade = await client.getContract("cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c");
|
||||
expect(jade).toEqual(
|
||||
const two = await client.getContract(deployedHackatom.instances[2].address);
|
||||
expect(two).toEqual(
|
||||
jasmine.objectContaining({
|
||||
address: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c",
|
||||
label: "JADE",
|
||||
address: deployedHackatom.instances[2].address,
|
||||
codeId: deployedHackatom.codeId,
|
||||
creator: alice.address0,
|
||||
label: deployedHackatom.instances[2].label,
|
||||
admin: alice.address1,
|
||||
}),
|
||||
);
|
||||
|
@ -30,8 +30,21 @@ export const base64Matcher = /^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|(?
|
||||
export const bech32AddressMatcher = /^[\x21-\x7e]{1,83}1[02-9ac-hj-np-z]{38}$/;
|
||||
|
||||
/** Deployed as part of scripts/wasmd/init.sh */
|
||||
export const deployedErc20 = {
|
||||
export const deployedHackatom = {
|
||||
codeId: 1,
|
||||
source: "https://crates.io/api/v1/crates/hackatom/not-yet-released/download",
|
||||
builder: "cosmwasm/rust-optimizer:0.9.1",
|
||||
checksum: "3defc33a41f58c71d38b176d521c411d8e74d26403fde7660486930c7579a016",
|
||||
instances: [
|
||||
{ address: "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", label: "From deploy_hackatom.js (0)" },
|
||||
{ address: "cosmos1hqrdl6wstt8qzshwc6mrumpjk9338k0lr4dqxd", label: "From deploy_hackatom.js (1)" },
|
||||
{ address: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c", label: "From deploy_hackatom.js (2)" },
|
||||
],
|
||||
};
|
||||
|
||||
/** Deployed as part of scripts/wasmd/init.sh */
|
||||
export const deployedErc20 = {
|
||||
codeId: 2,
|
||||
source: "https://crates.io/api/v1/crates/cw-erc20/not-yet-released/download",
|
||||
builder: "cosmwasm/rust-optimizer:0.9.0",
|
||||
checksum: "0f14abcc6fed08f2dd06896db974989db97dbcc6e8e30188b73fe5ab427c7785",
|
||||
|
@ -17,13 +17,35 @@ const alice = {
|
||||
|
||||
const codeMeta = {
|
||||
source: "https://crates.io/api/v1/crates/hackatom/not-yet-released/download",
|
||||
builder: "cosmwasm/rust-optimizer:0.9.0",
|
||||
builder: "cosmwasm/rust-optimizer:0.9.1",
|
||||
};
|
||||
|
||||
const initMsg = {
|
||||
beneficiary: alice.address0,
|
||||
verifier: alice.address0,
|
||||
};
|
||||
const inits = [
|
||||
{
|
||||
label: "From deploy_hackatom.js (0)",
|
||||
msg: {
|
||||
beneficiary: alice.address0,
|
||||
verifier: alice.address0,
|
||||
},
|
||||
admin: undefined,
|
||||
},
|
||||
{
|
||||
label: "From deploy_hackatom.js (1)",
|
||||
msg: {
|
||||
beneficiary: alice.address1,
|
||||
verifier: alice.address1,
|
||||
},
|
||||
admin: undefined,
|
||||
},
|
||||
{
|
||||
label: "From deploy_hackatom.js (2)",
|
||||
msg: {
|
||||
beneficiary: alice.address2,
|
||||
verifier: alice.address2,
|
||||
},
|
||||
admin: alice.address1,
|
||||
},
|
||||
];
|
||||
|
||||
async function main() {
|
||||
const wallet = await Secp256k1HdWallet.fromMnemonic(alice.mnemonic);
|
||||
@ -33,12 +55,13 @@ async function main() {
|
||||
const uploadReceipt = await client.upload(wasm, codeMeta, "Upload hackatom contract");
|
||||
console.info(`Upload succeeded. Receipt: ${JSON.stringify(uploadReceipt)}`);
|
||||
|
||||
const label = "From deploy_hackatom.js";
|
||||
const { contractAddress } = await client.instantiate(uploadReceipt.codeId, initMsg, label, {
|
||||
memo: `Create a hackatom instance in deploy_hackatom.js`,
|
||||
admin: alice.address0,
|
||||
});
|
||||
console.info(`Contract instantiated at ${contractAddress}`);
|
||||
for (const { label, msg, admin } of inits) {
|
||||
const { contractAddress } = await client.instantiate(uploadReceipt.codeId, msg, label, {
|
||||
memo: `Create a hackatom instance in deploy_hackatom.js`,
|
||||
admin: admin,
|
||||
});
|
||||
console.info(`Contract instantiated at ${contractAddress}`);
|
||||
}
|
||||
}
|
||||
|
||||
main().then(
|
||||
|
Loading…
x
Reference in New Issue
Block a user