-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decode delegation query response fails in Compartment due to undefined Decimal #9408
Comments
I have reproduced the error locally but not yet isolated a defect. Given import { Decimal } from "@cosmjs/math";
import * as math from "@cosmjs/math";
console.log(Decimal);
console.log(math);
console.log(math.Decimal); I get the correct behavior from Node.js and incorrect behavior from import "ses";
import url from "url";
import fs from "fs";
import { importLocation } from "@endo/compartment-mapper";
import { makeReadPowers } from "@endo/compartment-mapper/node-powers.js";
const readPowers = makeReadPowers({ url, fs });
const location = new URL("isolate-me.js", import.meta.url).href;
importLocation(readPowers, location, {
globals: { console },
}); The defect occurs at the boundary between an ESM/MJS module importing the CJS Given Object.defineProperty(exports, "__esModule", { value: true });
exports.b = void 0;
class B {}
exports.b = B; Given import { b } from "./b.cjs";
console.log(b); And this case works correctly in isolation under all of Node.js, importBundle, and importLocation. |
The culprit turns out to be the intermediate |
Thanks for the diagnosis! Our approach to endo compat so far has mostly been to patch the offending parts of cosmjs; for example, bn.js patch I'm not sure what would be the preferred tweak, but this seems to alleviate the symptoms: $ cat patches/@cosmjs+math+0.32.3.patch
diff --git a/node_modules/@cosmjs/math/build/index.js b/node_modules/@cosmjs/math/build/index.js
index 1f812f6..41f6398 100644
--- a/node_modules/@cosmjs/math/build/index.js
+++ b/node_modules/@cosmjs/math/build/index.js
@@ -2,7 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.Uint64 = exports.Uint53 = exports.Uint32 = exports.Int53 = exports.Decimal = void 0;
var decimal_1 = require("./decimal");
-Object.defineProperty(exports, "Decimal", { enumerable: true, get: function () { return decimal_1.Decimal; } });
+// Object.defineProperty(exports, "Decimal", { enumerable: true, get: function () { return decimal_1.Decimal; } });
+exports.Decimal = decimal_1.Decimal;
var integers_1 = require("./integers");
Object.defineProperty(exports, "Int53", { enumerable: true, get: function () { return integers_1.Int53; } });
Object.defineProperty(exports, "Uint32", { enumerable: true, get: function () { return integers_1.Uint32; } }); p.s. here's hoping for a |
Describe the bug
While working on
getDelegations
for theunbondExample.contract.js
, (#9070, #8863), I'm trying to useQueryDelegatorDelegationsResponse.decode(...)
from@agoric/cosmic-proto
inside a contract, but it fails due toDecimal
from@cosmjs/math
being undefined.To Reproduce
I reduced it to running this in a compartment:
3aa40db has a test for that and a test for using
QueryDelegatorDelegationsResponse.decode(...)
.yarn; yarn build
cd packages/orchestration
yarn test test/tx-encoding.test.ts -m 'compartment*'
Cannot read properties of undefined
yarn test run log
Expected behavior
QueryDelegatorDelegationsResponse.decode(...)
works inside a compartment just like it does outside a compartment.Platform Environment
cc @kriskowal @turadg @0xpatrickdev
The text was updated successfully, but these errors were encountered: