fix for sdk >= v50

+ remove parsedLogs
+ fix findAttribute
+ fill logs with []
This commit is contained in:
Pynix Wang
2024-03-08 12:25:22 +01:00
committed by Simon Warta
parent d7d9b7e353
commit a40cb78646
19 changed files with 1153 additions and 27 deletions
@@ -222,7 +222,7 @@ describe("CosmWasmClient", () => {
const signedTx = Uint8Array.from(TxRaw.encode(txRaw).finish());
const result = await client.broadcastTx(signedTx);
assertIsDeliverTxSuccess(result);
const amountAttr = logs.findAttribute(logs.parseRawLog(result.rawLog), "transfer", "amount");
const amountAttr = logs.findAttribute(result.events, "transfer", "amount");
expect(amountAttr.value).toEqual("1234567ucosm");
expect(result.transactionHash).toMatch(/^[0-9A-F]{64}$/);
});
@@ -385,12 +385,11 @@ describe("WasmExtension", () => {
{
const result = await uploadContract(wallet, getHackatom());
assertIsDeliverTxSuccess(result);
const parsedLogs = logs.parseLogs(logs.parseRawLog(result.rawLog));
const codeIdAttr = logs.findAttribute(parsedLogs, "store_code", "code_id");
const codeIdAttr = logs.findAttribute(result.events, "store_code", "code_id");
codeId = Number.parseInt(codeIdAttr.value, 10);
expect(codeId).toBeGreaterThanOrEqual(1);
expect(codeId).toBeLessThanOrEqual(200);
const actionAttr = logs.findAttribute(parsedLogs, "message", "module");
const actionAttr = logs.findAttribute(result.events, "message", "module");
expect(actionAttr.value).toEqual("wasm");
}
@@ -400,12 +399,11 @@ describe("WasmExtension", () => {
{
const result = await instantiateContract(wallet, codeId, beneficiaryAddress, funds);
assertIsDeliverTxSuccess(result);
const parsedLogs = logs.parseLogs(logs.parseRawLog(result.rawLog));
const contractAddressAttr = logs.findAttribute(parsedLogs, "instantiate", "_contract_address");
const contractAddressAttr = logs.findAttribute(result.events, "instantiate", "_contract_address");
contractAddress = contractAddressAttr.value;
const amountAttr = logs.findAttribute(parsedLogs, "transfer", "amount");
const amountAttr = logs.findAttribute(result.events, "transfer", "amount");
expect(amountAttr.value).toEqual("1234ucosm,321ustake");
const actionAttr = logs.findAttribute(parsedLogs, "message", "module");
const actionAttr = logs.findAttribute(result.events, "message", "module");
expect(actionAttr.value).toEqual("wasm");
const balanceUcosm = await client.bank.balance(contractAddress, "ucosm");
@@ -418,8 +416,7 @@ describe("WasmExtension", () => {
{
const result = await executeContract(wallet, contractAddress, { release: {} });
assertIsDeliverTxSuccess(result);
const parsedLogs = logs.parseLogs(logs.parseRawLog(result.rawLog));
const wasmEvent = parsedLogs.find(() => true)?.events.find((e) => e.type === "wasm");
const wasmEvent = result.events.find((e) => e.type === "wasm");
assert(wasmEvent, "Event of type wasm expected");
expect(wasmEvent.attributes).toContain({ key: "action", value: "release" });
expect(wasmEvent.attributes).toContain({
@@ -63,6 +63,7 @@ import {
wasmTypes,
} from "./modules";
export interface UploadResult {
/** A hex encoded sha256 checksum of the original Wasm code (that is stored on chain) */
readonly checksum: string;
@@ -288,14 +289,13 @@ export class SigningCosmWasmClient extends CosmWasmClient {
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
const parsedLogs = logs.parseRawLog(result.rawLog);
const codeIdAttr = logs.findAttribute(parsedLogs, "store_code", "code_id");
const codeIdAttr = logs.findAttribute(result.events, "store_code", "code_id");
return {
checksum: toHex(sha256(wasmCode)),
originalSize: wasmCode.length,
compressedSize: compressed.length,
codeId: Number.parseInt(codeIdAttr.value, 10),
logs: parsedLogs,
logs: [],
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
@@ -327,11 +327,10 @@ export class SigningCosmWasmClient extends CosmWasmClient {
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
const parsedLogs = logs.parseRawLog(result.rawLog);
const contractAddressAttr = logs.findAttribute(parsedLogs, "instantiate", "_contract_address");
const contractAddressAttr = logs.findAttribute(result.events, "instantiate", "_contract_address");
return {
contractAddress: contractAddressAttr.value,
logs: parsedLogs,
logs: [],
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
@@ -366,11 +365,10 @@ export class SigningCosmWasmClient extends CosmWasmClient {
if (isDeliverTxFailure(result)) {
throw new Error(createDeliverTxResponseErrorMessage(result));
}
const parsedLogs = logs.parseRawLog(result.rawLog);
const contractAddressAttr = logs.findAttribute(parsedLogs, "instantiate", "_contract_address");
const contractAddressAttr = logs.findAttribute(result.events, "instantiate", "_contract_address");
return {
contractAddress: contractAddressAttr.value,
logs: parsedLogs,
logs: [],
height: result.height,
transactionHash: result.transactionHash,
events: result.events,
+2 -3
View File
@@ -69,9 +69,8 @@ export function parseRawLog(input = "[]"): readonly Log[] {
*
* Throws if the attribute was not found.
*/
export function findAttribute(logs: readonly Log[], eventType: string, attrKey: string): Attribute {
const firstLogs = logs.find(() => true);
const out = firstLogs?.events
export function findAttribute(events: readonly Event[], eventType: string, attrKey: string): Attribute {
const out = events
.find((event) => event.type === eventType)
?.attributes.find((attr) => attr.key === attrKey);
if (!out) {