Skip to content

Commit

Permalink
Refactor and remove need for init script
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Jun 21, 2021
1 parent 95b61ca commit 71d5a36
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 32 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ jobs:
timeout 60 bash -c "until curl -s http://localhost:26655/status > /dev/null; do sleep 0.5; done"
sleep 1
echo "Chains up and running!"
- run:
name: Upload wasm contracts
command: ./scripts/wasmd/init.sh
- run:
command: yarn test
- run:
Expand Down
8 changes: 1 addition & 7 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ These are long-living commands and will keep running indefinitely
./scripts/gaia/start.sh
```

Once they are all started, you need to upload the wasm contracts. This will return quickly, so you can reuse the console:

```sh
./scripts/wasmd/init.sh
```

When you are done, you can run the following in any console:
When you are done running tests, you can run the following in any console to shut down the chains:

```sh
./scripts/simapp/stop.sh
Expand Down
16 changes: 0 additions & 16 deletions scripts/wasmd/deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,6 @@ const contracts = [
},
];

// const addresses = [
// "wasm1lk46aknye76sgfv65v5zcyyld0fnuu5jg02hs8",
// ];
// const initDataHash = {
// admin: undefined,
// initMsg: {
// decimals: 5,
// name: "Hash token",
// symbol: "HASH",
// initial_balances: addresses.map((address) => ({
// address,
// amount: "123456",
// })),
// },
// };

async function downloadWasm(url) {
const r = await axios.get(url, { responseType: 'arraybuffer' });
if (r.status !== 200) {
Expand Down
73 changes: 67 additions & 6 deletions src/lib/cosmwasm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,73 @@
import { fromUtf8, toBase64, toUtf8 } from '@cosmjs/encoding';
import { assert } from '@cosmjs/utils';
import test from 'ava';
import axios from 'axios';

import { Link } from './link';
import { CosmWasmSigner, ics20, setup, setupWasmClient } from './testutils';

const codeIds = {
cw20: 1,
ics20: 2,
const codeIds: Record<string, number> = {
cw20: 0,
ics20: 0,
};

interface WasmData {
wasmUrl: string;
codeMeta: {
source: string;
builder: string;
};
}

const contracts: Record<string, WasmData> = {
cw20: {
wasmUrl:
'https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.6.1/cw20_base.wasm',
codeMeta: {
source:
'https://github.com/CosmWasm/cosmwasm-plus/tree/v0.6.0/contracts/cw20-base',
builder: 'cosmwasm/workspace-optimizer:0.11.0',
},
},
ics20: {
wasmUrl:
'https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.6.1/cw20_ics20.wasm',
codeMeta: {
source:
'https://github.com/CosmWasm/cosmwasm-plus/tree/v0.6.0/contracts/cw20-ics20',
builder: 'cosmwasm/workspace-optimizer:0.11.0',
},
},
};

async function downloadWasm(url: string) {
const r = await axios.get(url, { responseType: 'arraybuffer' });
if (r.status !== 200) {
throw new Error(`Download error: ${r.status}`);
}
return r.data;
}

test.before(async (t) => {
const cosmwasm = await setupWasmClient();

for (const name in contracts) {
const contract = contracts[name];
console.info(`Downloading ${name} at ${contract.wasmUrl}...`);
const wasm = await downloadWasm(contract.wasmUrl);
const receipt = await cosmwasm.sign.upload(
cosmwasm.senderAddress,
wasm,
contract.codeMeta,
`Upload ${name}`
);
console.debug(`Upload ${name} with CodeID: ${receipt.codeId}`);
codeIds[name] = receipt.codeId;
}

t.pass();
});

// creates it with 6 decimal places
// provides 123456.789 tokens to the creator
function cw20init(owner: string, symbol: string): Record<string, unknown> {
Expand Down Expand Up @@ -99,7 +157,7 @@ test.serial('set up channel with ics20 contract', async (t) => {
);
});

test.only('send packets with ics20 contract', async (t) => {
test.serial('send packets with ics20 contract', async (t) => {
const cosmwasm = await setupWasmClient();

// instantiate cw20
Expand Down Expand Up @@ -175,6 +233,10 @@ test.only('send packets with ics20 contract', async (t) => {
// move it and the ack
const txAcks = await link.relayPackets('B', packets);
t.is(txAcks.length, 1);
const parsedAck1 = JSON.parse(fromUtf8(txAcks[0].acknowledgement));
t.truthy(parsedAck1.result);
t.falsy(parsedAck1.error);

// need to wait briefly for it to be indexed
await src.waitOneBlock();
// and send the acks over
Expand Down Expand Up @@ -229,14 +291,13 @@ test.only('send packets with ics20 contract', async (t) => {
);
await src.waitOneBlock();

// relaye this packet
// relay this packet
const packets3 = await link.getPendingPackets('A');
t.is(packets3.length, 1);
const txAcks3 = await link.relayPackets('A', packets3);
t.is(txAcks3.length, 1);
// and expect error on ack
const parsedAck = JSON.parse(fromUtf8(txAcks3[0].acknowledgement));
console.log(parsedAck);
t.truthy(parsedAck.error);
t.falsy(parsedAck.result);
});
6 changes: 6 additions & 0 deletions src/lib/testutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ export async function signingCosmWasmClient(
// This is just for tests - don't add this in production code
broadcastPollIntervalMs: 300,
broadcastTimeoutMs: 2000,
gasLimits: {
upload: 1750000,
},
};
const sign = await SigningCosmWasmClient.connectWithSigner(
opts.tendermintUrlHttp,
Expand Down Expand Up @@ -261,6 +264,9 @@ export async function fundAccount(
const feeTokens = {
amount,
denom: GasPrice.fromString(opts.minFee).denom,
gasLimits: {
upload: 1750000,
},
};
await client.sendTokens(rcpt, [feeTokens]);
}
Expand Down

0 comments on commit 71d5a36

Please sign in to comment.