Skip to content
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

Fix encoding filter topics for bytesX param #4244

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion src.ts/_tests/test-abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,54 @@ describe("Test Bytes32 strings", function() {
});

describe("Test Interface", function() {
const eventABI = {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "bytes20",
name: "walletPubKeyHash",
type: "bytes20",
},
{
indexed: false,
internalType: "bytes",
name: "redeemerOutputScript",
type: "bytes",
},
{
indexed: true,
internalType: "address",
name: "redeemer",
type: "address",
},
{
indexed: false,
internalType: "uint64",
name: "requestedAmount",
type: "uint64",
},
{
indexed: false,
internalType: "uint64",
name: "treasuryFee",
type: "uint64",
},
{
indexed: false,
internalType: "uint64",
name: "txMaxFee",
type: "uint64",
},
],
name: "RedemptionRequested",
type: "event",
};

const iface = new Interface([
"function balanceOf(address owner) returns (uint)",
"event Transfer(address indexed from, address indexed to, uint amount)"
"event Transfer(address indexed from, address indexed to, uint amount)",
eventABI,
]);

it("does interface stuff; @TODO expand this", function() {
Expand Down Expand Up @@ -111,6 +156,17 @@ describe("Test Interface", function() {
assert.equal(filter[1], "0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72");
assert.equal(filter[2], "0x000000000000000000000000ac1639cf97a3a46d431e6d1216f576622894cbb5");

// Data from:
// https://goerli.etherscan.io/tx/0xe61cef4cd706db8e23114717a207d76cc6b0df0b74ec52805551c4d1bf347a27#eventlog
// see `RedemptionRequested` event.
const walletPubKeyHash = "0x03b74d6893ad46dfdd01b9e0e3b3385f4fce2d1e"
const redeemer = "0x086813525A7dC7dafFf015Cdf03896Fd276eab60"
const filterWithBytes20 = iface.encodeFilterTopics("RedemptionRequested", [ walletPubKeyHash, undefined, redeemer ]);
assert.equal(filterWithBytes20.length, 3);
assert.equal(filterWithBytes20[0], "0x97a0199072f487232635d50ab75860891afe0b91c976ed2fc76502c4d82d0d95");
assert.equal(filterWithBytes20[1], "0x03b74d6893ad46dfdd01b9e0e3b3385f4fce2d1e000000000000000000000000");
assert.equal(filterWithBytes20[2], "0x000000000000000000000000086813525a7dc7dafff015cdf03896fd276eab60");

const eventLog = iface.encodeEventLog("Transfer", [ addr, addr2, 234 ]);
assert.equal(eventLog.data, "0x00000000000000000000000000000000000000000000000000000000000000ea");
assert.deepEqual(eventLog.topics, [
Expand Down
2 changes: 2 additions & 0 deletions src.ts/abi/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,8 @@ export class Interface {
return id(value);
} else if (param.type === "bytes") {
return keccak256(hexlify(value));
} else if (param.type.match(/^bytes(\d+)$/)) {
return this.#abiCoder.encode([param.type], [value]);
}

if (param.type === "bool" && typeof(value) === "boolean") {
Expand Down