Skip to content

Commit

Permalink
fix ens name resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
gregfromstl committed Dec 18, 2024
1 parent 64a5ee3 commit 74f9762
Show file tree
Hide file tree
Showing 8 changed files with 520 additions and 514 deletions.
28 changes: 14 additions & 14 deletions packages/thirdweb/src/auth/parse-erc6492-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Erc6492Signature } from "./types.js";
* @auth
*/
export type ParseErc6492SignatureReturnType = OneOf<
Erc6492Signature | { signature: Hex }
Erc6492Signature | { signature: Hex }
>;

/**
Expand All @@ -29,19 +29,19 @@ export type ParseErc6492SignatureReturnType = OneOf<
* @auth
*/
export function parseErc6492Signature(
signature: Hex,
signature: Hex,
): ParseErc6492SignatureReturnType {
if (!ox__WrappedSignature.validate(signature)) {
return { signature };
}
if (!ox__WrappedSignature.validate(signature)) {
return { signature };
}

const [address, data, originalSignature] = ox__AbiParameters.decode(
[{ type: "address" }, { type: "bytes" }, { type: "bytes" }],
signature,
);
return {
address: ox__Address.checksum(address),
data,
signature: originalSignature,
};
const [address, data, originalSignature] = ox__AbiParameters.decode(
[{ type: "address" }, { type: "bytes" }, { type: "bytes" }],
signature,
);
return {
address: ox__Address.checksum(address),
data,
signature: originalSignature,
};
}
246 changes: 123 additions & 123 deletions packages/thirdweb/src/event/actions/get-events.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it } from "vitest";
import { FORK_BLOCK_NUMBER } from "../../../test/src/chains.js";
import {
DOODLES_CONTRACT,
USDT_CONTRACT,
DOODLES_CONTRACT,
USDT_CONTRACT,
} from "../../../test/src/test-contracts.js";
import { transferEvent } from "../../extensions/erc721/__generated__/IERC721A/events/Transfer.js";
import { prepareEvent } from "../prepare-event.js";
Expand All @@ -11,136 +11,136 @@ import { getContractEvents } from "./get-events.js";
// skip this test suite if there is no secret key available to test with
// TODO: remove reliance on secret key during unit tests entirely
describe.runIf(process.env.TW_SECRET_KEY)("getEvents", () => {
it("should get all events", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 10n,
});
expect(events.length).toBe(261);
});
it("should get all events", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 10n,
});
expect(events.length).toBe(261);
});

// TODO: investigate why RPC returns 0 events here
it.skip("should get events for blockHash", async () => {
const BLOCK_HASH =
"0xb0ad5ee7b4912b50e5a2d7993796944653a4c0632c57740fe4a7a1c61e426324";
const events = await getContractEvents({
contract: USDT_CONTRACT,
blockHash: BLOCK_HASH,
});
// TODO: investigate why RPC returns 0 events here
it.skip("should get events for blockHash", async () => {
const BLOCK_HASH =
"0xb0ad5ee7b4912b50e5a2d7993796944653a4c0632c57740fe4a7a1c61e426324";
const events = await getContractEvents({
contract: USDT_CONTRACT,
blockHash: BLOCK_HASH,
});

expect(events.length).toBe(14);
});
expect(events.length).toBe(14);
});

it("should get events for blockRange", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
blockRange: 10n,
});
expect(events.length).toBe(241);
it("should get events for blockRange", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
blockRange: 10n,
});
expect(events.length).toBe(241);

const explicitEvents = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 9n, // 1 less than range as fromBlock and toBlock are inclusive
toBlock: FORK_BLOCK_NUMBER,
});
expect(explicitEvents.length).toEqual(events.length);
});
const explicitEvents = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 9n, // 1 less than range as fromBlock and toBlock are inclusive
toBlock: FORK_BLOCK_NUMBER,
});
expect(explicitEvents.length).toEqual(events.length);
});

it("should get events for blockRange using fromBlock and toBlock", async () => {
const eventsFromBlock = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 49n,
blockRange: 20n,
});
expect(eventsFromBlock.length).toBe(412);
it("should get events for blockRange using fromBlock and toBlock", async () => {
const eventsFromBlock = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 49n,
blockRange: 20n,
});
expect(eventsFromBlock.length).toBe(412);

const eventsToBlock = await getContractEvents({
contract: USDT_CONTRACT,
toBlock: FORK_BLOCK_NUMBER - 30n,
blockRange: 20n,
});
expect(eventsToBlock.length).toBe(eventsFromBlock.length);
const eventsToBlock = await getContractEvents({
contract: USDT_CONTRACT,
toBlock: FORK_BLOCK_NUMBER - 30n,
blockRange: 20n,
});
expect(eventsToBlock.length).toBe(eventsFromBlock.length);

const explicitEvents = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 49n,
toBlock: FORK_BLOCK_NUMBER - 30n,
});
expect(explicitEvents.length).toEqual(eventsFromBlock.length);
});
const explicitEvents = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 49n,
toBlock: FORK_BLOCK_NUMBER - 30n,
});
expect(explicitEvents.length).toEqual(eventsFromBlock.length);
});

it("should get individual events with signature", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 100n,
events: [
prepareEvent({
signature: "event Burn(address indexed burner, uint256 amount)",
}),
],
});
expect(events.length).toMatchInlineSnapshot("0");
});
it("should get individual events with signature", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 100n,
events: [
prepareEvent({
signature: "event Burn(address indexed burner, uint256 amount)",
}),
],
});
expect(events.length).toMatchInlineSnapshot("0");
});

it("should get specified events", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 10n,
events: [
prepareEvent({
signature: "event Burn(address indexed burner, uint256 amount)",
}),
prepareEvent({
signature: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "owner",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "spender",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "value",
type: "uint256",
},
],
name: "Approval",
type: "event",
},
}),
],
});
expect(events.length).toMatchInlineSnapshot("9");
});
it("should get specified events", async () => {
const events = await getContractEvents({
contract: USDT_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 10n,
events: [
prepareEvent({
signature: "event Burn(address indexed burner, uint256 amount)",
}),
prepareEvent({
signature: {
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "owner",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "spender",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "value",
type: "uint256",
},
],
name: "Approval",
type: "event",
},
}),
],
});
expect(events.length).toMatchInlineSnapshot("9");
});

it("should get individual events with extension", async () => {
const events = await getContractEvents({
contract: DOODLES_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 1000n,
events: [transferEvent()],
});
expect(events.length).toBe(38);
});
it("should get individual events with extension", async () => {
const events = await getContractEvents({
contract: DOODLES_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 1000n,
events: [transferEvent()],
});
expect(events.length).toBe(38);
});

it("should get individual events with filters", async () => {
const events = await getContractEvents({
contract: DOODLES_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 1000n,
events: [
transferEvent({
from: "0xB81965DdFdDA3923f292a47A1be83ba3A36B5133",
}),
],
});
expect(events.length).toBe(2);
});
it("should get individual events with filters", async () => {
const events = await getContractEvents({
contract: DOODLES_CONTRACT,
fromBlock: FORK_BLOCK_NUMBER - 1000n,
events: [
transferEvent({
from: "0xB81965DdFdDA3923f292a47A1be83ba3A36B5133",
}),
],
});
expect(events.length).toBe(2);
});
});
Loading

0 comments on commit 74f9762

Please sign in to comment.