Don't randomize hackatom
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
deployedErc20,
|
||||
faucet,
|
||||
fromOneElementArray,
|
||||
getRandomizedHackatom,
|
||||
getHackatom,
|
||||
makeRandomAddress,
|
||||
pendingWithoutWasmd,
|
||||
semverMatcher,
|
||||
@@ -92,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(
|
||||
@@ -738,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);
|
||||
|
||||
@@ -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[] = [
|
||||
|
||||
@@ -25,31 +25,8 @@ export function leb128Encode(uint: number): Uint8Array {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user