Merge pull request #143 from CosmWasm/update-wasmd

Update wasmd to 0.7.1
This commit is contained in:
Simon Warta 2020-03-12 21:18:06 +01:00 committed by GitHub
commit eaa3189e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 78 deletions

View File

@ -13,7 +13,7 @@ import cosmoshub from "./testdata/cosmoshub.json";
import {
deployedErc20,
faucet,
getRandomizedHackatom,
getHackatom,
makeRandomAddress,
pendingWithoutWasmd,
tendermintIdMatcher,
@ -376,7 +376,7 @@ describe("CosmWasmClient", () => {
const client = new SigningCosmWasmClient(wasmd.endpoint, faucet.address, signBytes =>
pen.sign(signBytes),
);
const { codeId } = await client.upload(getRandomizedHackatom());
const { codeId } = await client.upload(getHackatom());
const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() };
const { contractAddress } = await client.instantiate(codeId, initMsg, "random hackatom");
contract = { initMsg: initMsg, address: contractAddress };
@ -429,7 +429,7 @@ describe("CosmWasmClient", () => {
const client = new SigningCosmWasmClient(wasmd.endpoint, faucet.address, signBytes =>
pen.sign(signBytes),
);
const { codeId } = await client.upload(getRandomizedHackatom());
const { codeId } = await client.upload(getHackatom());
const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() };
const { contractAddress } = await client.instantiate(codeId, initMsg, "a different hackatom");
contract = { initMsg: initMsg, address: contractAddress };

View File

@ -16,9 +16,10 @@ import {
deployedErc20,
faucet,
fromOneElementArray,
getRandomizedHackatom,
getHackatom,
makeRandomAddress,
pendingWithoutWasmd,
semverMatcher,
tendermintAddressMatcher,
tendermintHeightMatcher,
tendermintIdMatcher,
@ -91,7 +92,7 @@ async function uploadCustomContract(
}
async function uploadContract(client: RestClient, pen: Pen): Promise<PostTxsResponse> {
return uploadCustomContract(client, pen, getRandomizedHackatom());
return uploadCustomContract(client, pen, getHackatom());
}
async function instantiateContract(
@ -315,7 +316,7 @@ describe("RestClient", () => {
name: "wasm",
server_name: "wasmd",
client_name: "wasmcli",
version: jasmine.stringMatching(/^0\.7\.[0-9]+(-[a-zA-Z0-9._]+)?$/),
version: jasmine.stringMatching(semverMatcher),
commit: jasmine.stringMatching(tendermintShortHashMatcher),
build_tags: "netgo,ledger",
go: jasmine.stringMatching(/^go version go1\.[0-9]+\.[0-9]+ linux\/amd64$/),
@ -737,7 +738,7 @@ describe("RestClient", () => {
const numExisting = existingInfos.length;
// upload data
const wasmCode = getRandomizedHackatom();
const wasmCode = getHackatom();
const result = await uploadCustomContract(client, pen, wasmCode);
expect(result.code).toBeFalsy();
const logs = parseLogs(result.logs);

View File

@ -6,7 +6,7 @@ import { PrivateCosmWasmClient } from "./cosmwasmclient";
import { Secp256k1Pen } from "./pen";
import { RestClient } from "./restclient";
import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient";
import { getRandomizedHackatom, makeRandomAddress, pendingWithoutWasmd } from "./testutils.spec";
import { getHackatom, makeRandomAddress, pendingWithoutWasmd } from "./testutils.spec";
import { Coin } from "./types";
const { toHex } = Encoding;
@ -55,7 +55,7 @@ describe("SigningCosmWasmClient", () => {
pendingWithoutWasmd();
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
const wasm = getRandomizedHackatom();
const wasm = getHackatom();
const {
codeId,
originalChecksum,
@ -74,7 +74,7 @@ describe("SigningCosmWasmClient", () => {
pendingWithoutWasmd();
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
const wasm = getRandomizedHackatom();
const wasm = getHackatom();
const meta: UploadMeta = {
source: "https://crates.io/api/v1/crates/cw-nameservice/0.1.0/download",
@ -93,7 +93,7 @@ describe("SigningCosmWasmClient", () => {
pendingWithoutWasmd();
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
const { codeId } = await client.upload(getRandomizedHackatom());
const { codeId } = await client.upload(getHackatom());
const transferAmount: readonly Coin[] = [
{
@ -126,7 +126,7 @@ describe("SigningCosmWasmClient", () => {
pendingWithoutWasmd();
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
const { codeId } = await client.upload(getRandomizedHackatom());
const { codeId } = await client.upload(getHackatom());
const contractAddress1 = await client.instantiate(
codeId,
@ -153,7 +153,7 @@ describe("SigningCosmWasmClient", () => {
pendingWithoutWasmd();
const pen = await Secp256k1Pen.fromMnemonic(faucet.mnemonic);
const client = new SigningCosmWasmClient(httpUrl, faucet.address, signBytes => pen.sign(signBytes));
const { codeId } = await client.upload(getRandomizedHackatom());
const { codeId } = await client.upload(getHackatom());
// instantiate
const transferAmount: readonly Coin[] = [

View File

@ -3,53 +3,8 @@ import { Bech32, Encoding } from "@iov/encoding";
import hackatom from "./testdata/contract.json";
const { fromHex } = Encoding;
export function leb128Encode(uint: number): Uint8Array {
if (uint < 0) throw new Error("Only non-negative values supported");
if (uint > 0x7fffffff) throw new Error("Only values in signed int32 range allowed");
const out = new Array<number>();
let value = uint;
do {
// eslint-disable-next-line no-bitwise
let byte = value & 0b01111111;
// eslint-disable-next-line no-bitwise
value >>= 7;
// more bytes to come: set high order bit of byte
// eslint-disable-next-line no-bitwise
if (value !== 0) byte ^= 0b10000000;
out.push(byte);
} while (value !== 0);
return new Uint8Array(out);
}
export function getRandomizedHackatom(): Uint8Array {
const data = Encoding.fromBase64(hackatom.data);
// The return value of the export function cosmwasm_api_0_6 is unused and
// can be randomized for testing.
//
// Find position of mutable bytes as follows:
// $ wasm-objdump -d contract.wasm | grep -F "cosmwasm_api_0_6" -A 1
// 0136d2 func[198] <cosmwasm_api_0_6>:
// 0136d3: 41 83 0c | i32.const 1539
//
// In the last line, the addresses [0136d3, 0136d3+1, 0136d3+2] hold a one byte instruction
// and a two byte value (leb128 encoded 1539). See also
// https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#constants-described-here.
// Any unsigned integer from 128 to 16383 is encoded to two leb128 bytes
const min = 128;
const max = 16383;
const random = Math.floor(Math.random() * (max - min)) + min;
const bytes = leb128Encode(random);
data[0x0136d3 + 1] = bytes[0];
data[0x0136d3 + 2] = bytes[1];
return data;
export function getHackatom(): Uint8Array {
return Encoding.fromBase64(hackatom.data);
}
export function makeRandomAddress(): string {
@ -61,6 +16,7 @@ export const tendermintIdMatcher = /^[0-9A-F]{64}$/;
export const tendermintOptionalIdMatcher = /^([0-9A-F]{64}|)$/;
export const tendermintAddressMatcher = /^[0-9A-F]{40}$/;
export const tendermintShortHashMatcher = /^[0-9a-f]{40}$/;
export const semverMatcher = /^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
// https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#bech32
export const bech32AddressMatcher = /^[\x21-\x7e]{1,83}1[02-9ac-hj-np-z]{38}$/;
@ -108,20 +64,3 @@ export function fromOneElementArray<T>(elements: ArrayLike<T>): T {
if (elements.length !== 1) throw new Error(`Expected exactly one element but got ${elements.length}`);
return elements[0];
}
describe("leb128", () => {
describe("leb128Encode", () => {
it("works for single byte values", () => {
// Values in 7 bit range are encoded as one byte
expect(leb128Encode(0)).toEqual(fromHex("00"));
expect(leb128Encode(20)).toEqual(fromHex("14"));
expect(leb128Encode(127)).toEqual(fromHex("7f"));
});
it("works for multi byte values", () => {
// from external souce (wasm-objdump)
expect(leb128Encode(145)).toEqual(fromHex("9101"));
expect(leb128Encode(1539)).toEqual(fromHex("830c"));
});
});
});

View File

@ -1,5 +1,5 @@
# Choose from https://hub.docker.com/r/cosmwasm/wasmd-demo/tags
REPOSITORY="cosmwasm/wasmd-demo"
VERSION="v0.7.0"
VERSION="v0.7.1"
CONTAINER_NAME="wasmd"