Skip to content

Commit

Permalink
[ADHOC] feat(sdk): mandatory knownSignatures for validation (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord authored Oct 22, 2024
1 parent e08f218 commit 9860502
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
],
"commit": false,
"fixed": [["@boostxyz/*"]],
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/curly-rice-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@boostxyz/sdk": minor
---

make `ValidationActionStepParams.knownSignatures` mandatory. Cuts down on size via dep removal, better dx
3 changes: 3 additions & 0 deletions examples/agora-vote/src/agora-vote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import events from '@boostxyz/signatures/events';
import functions from '@boostxyz/signatures/functions';
import { accounts } from '@boostxyz/test/accounts';
import { allKnownSignatures } from '@boostxyz/test/allKnownSignatures';
import {
type BudgetFixtures,
type Fixtures,
Expand Down Expand Up @@ -148,6 +149,7 @@ describe('Boost with Voting Incentive', () => {
asset: erc20.assertValidAddress(),
reward: parseEther('0.1'),
limit: parseEther('1'),
manager: owner,
}),
],
});
Expand Down Expand Up @@ -194,6 +196,7 @@ describe('Boost with Voting Incentive', () => {
});
const validation = await action.validateActionSteps({
logs,
knownSignatures: allKnownSignatures,
});
expect(validation).toBe(true);

Expand Down
3 changes: 2 additions & 1 deletion examples/delegate-action/src/delegate-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { StrategyType } from '@boostxyz/sdk/claiming';
import { selectors } from '@boostxyz/signatures/events';
import { accounts } from '@boostxyz/test/accounts';
import { allKnownSignatures } from '@boostxyz/test/allKnownSignatures';
import {
type BudgetFixtures,
type Fixtures,
Expand Down Expand Up @@ -158,7 +159,7 @@ describe('Boost with Delegate Action Incentive', () => {

// Make sure that the transaction was sent as expected and validates the action
expect(testReceipt).toBeDefined();
const validation = await action.validateActionSteps();
const validation = await action.validateActionSteps({ hash: testReceipt, chainId: base.id, knownSignatures: allKnownSignatures });
expect(validation).toBe(true);
// Generate the signature using the trusted signer
const claimDataPayload = await boost.validator.encodeClaimData({
Expand Down
3 changes: 2 additions & 1 deletion examples/ens-register/src/ens-register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { StrategyType } from '@boostxyz/sdk/claiming';
import { selectors } from '@boostxyz/signatures/functions';
import { accounts } from '@boostxyz/test/accounts';
import { allKnownSignatures } from '@boostxyz/test/allKnownSignatures';
import {
type BudgetFixtures,
type Fixtures,
Expand Down Expand Up @@ -173,7 +174,7 @@ describe('Boost with ENS Registration Incentive', () => {
// Make sure that the transaction was sent as expected and validates the action
expect(hash).toBeDefined();

const validation = await action.validateActionSteps({ hash });
const validation = await action.validateActionSteps({ hash, chainId: sepolia.id, knownSignatures: allKnownSignatures });
expect(validation).toBe(true);
// Generate the signature using the trusted signer
const claimDataPayload = await boost.validator.encodeClaimData({
Expand Down
3 changes: 2 additions & 1 deletion examples/swap-specific-dex/src/swap-specific-dex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
fundBudget,
} from '@boostxyz/test/helpers';
import { setupConfig, testAccount } from '@boostxyz/test/viem';
import { allKnownSignatures } from '@boostxyz/test/allKnownSignatures';

const walletClient = createTestClient({
transport: http("http://127.0.0.1:8545"),
Expand Down Expand Up @@ -156,7 +157,7 @@ describe('Boost for Swapping on a Specific DEX (paraswap)', () => {

// Make sure that the transaction was sent as expected and validates the action
expect(hash).toBeDefined();
const validation = await action.validateActionSteps({ hash });
const validation = await action.validateActionSteps({ hash, chainId: arbitrum.id, knownSignatures: allKnownSignatures });
expect(validation).toBe(true);
// Generate the signature using the trusted signer
const claimDataPayload = await boost.validator.encodeClaimData({
Expand Down
2 changes: 2 additions & 0 deletions examples/zora-mint/src/zora-mint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { StrategyType } from '@boostxyz/sdk/claiming';
import { selectors } from '@boostxyz/signatures/events';
import { accounts } from '@boostxyz/test/accounts';
import { allKnownSignatures } from '@boostxyz/test/allKnownSignatures';
import {
type BudgetFixtures,
type Fixtures,
Expand Down Expand Up @@ -163,6 +164,7 @@ describe('Boost with NFT Minting Incentive', () => {
const validation = await action.validateActionSteps({
hash: txHash,
chainId,
knownSignatures: allKnownSignatures,
});
expect(validation).toBe(true);
// Generate the signature using the trusted signer
Expand Down
32 changes: 19 additions & 13 deletions packages/sdk/src/Actions/EventAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { selectors as eventSelectors } from "@boostxyz/signatures/events";
import { selectors as funcSelectors } from "@boostxyz/signatures/functions";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import {
type AbiEvent,
AbiEvent,
AbiFunction,
type Address,
type GetLogsReturnType,
type Hex,
type Log,
isAddress,
pad,
parseEther,
toHex,
zeroAddress,
Expand Down Expand Up @@ -37,6 +35,7 @@ import {
Criteria,
anyActionParameter,
} from "./EventAction";
import { allKnownSignatures } from "@boostxyz/test/allKnownSignatures";

let fixtures: Fixtures,
erc721: MockERC721,
Expand Down Expand Up @@ -414,7 +413,7 @@ describe("EventAction Event Selector", () => {
const recipient = accounts[1].account;
await erc721.approve(recipient, 1n);
const { hash } = await erc721.transferFromRaw(defaultOptions.account.address, recipient, 1n);
expect(await action.validateActionSteps({ hash, chainId })).toBe(true);
expect(await action.validateActionSteps({ hash, chainId, knownSignatures: allKnownSignatures })).toBe(true);
});

test("can supply your own logs to validate against", async () => {
Expand Down Expand Up @@ -446,7 +445,7 @@ describe("EventAction Event Selector", () => {
},
];
const action = await loadFixture(cloneEventAction(fixtures, erc721));
expect(await action.validateActionSteps({ hash, chainId, logs })).toBe(true);
expect(await action.validateActionSteps({ hash, chainId, logs, knownSignatures: allKnownSignatures })).toBe(true);
});

describe("string event actions", () => {
Expand All @@ -464,7 +463,7 @@ describe("EventAction Event Selector", () => {
);

const hash = await stringEmitterFixtures.emitIndexedString("Hello world");
await expect(() => action.validateActionSteps({ hash, chainId })).rejects.toThrowError(
await expect(() => action.validateActionSteps({ hash, chainId, knownSignatures: allKnownSignatures })).rejects.toThrowError(
/Parameter is not transparently stored onchain/,
);
});
Expand All @@ -481,7 +480,7 @@ describe("EventAction Event Selector", () => {
),
);
const hash = await stringEmitterFixtures.emitString("Hello world");
expect(await action.validateActionSteps({ hash, chainId })).toBe(true);
expect(await action.validateActionSteps({ hash, chainId, knownSignatures: allKnownSignatures })).toBe(true);
});
test("can parse and validate regex for an emitted string event", async () => {
const action = await loadFixture(
Expand All @@ -497,7 +496,7 @@ describe("EventAction Event Selector", () => {
);

const hash = await stringEmitterFixtures.emitString("Hello world");
expect(await action.validateActionSteps({ hash, chainId })).toBe(true);
expect(await action.validateActionSteps({ hash, chainId, knownSignatures: allKnownSignatures })).toBe(true);
});
});

Expand All @@ -510,6 +509,7 @@ describe("EventAction Event Selector", () => {
await action.deriveActionClaimantFromTransaction(await action.getActionClaimant(), {
hash,
chainId,
knownSignatures: allKnownSignatures
}),
).toBe(recipient);
});
Expand All @@ -525,6 +525,7 @@ describe("EventAction Event Selector", () => {
await action.deriveActionClaimantFromTransaction(await action.getActionClaimant(), {
hash,
chainId,
knownSignatures: allKnownSignatures
}),
).toBe(recipient);
});
Expand All @@ -534,7 +535,7 @@ describe("EventAction Event Selector", () => {
const recipient = accounts[1].account;
await erc721.approve(recipient, 1n);
const { hash } = await erc721.transferFromRaw(defaultOptions.account.address, recipient, 1n);
expect(await action.validateActionSteps({ hash, chainId })).toBe(true);
expect(await action.validateActionSteps({ hash, chainId, knownSignatures: allKnownSignatures })).toBe(true);
})
});
});
Expand Down Expand Up @@ -690,7 +691,7 @@ describe("EventAction Func Selector", () => {
});

expect(
await action.isActionStepValid(actionStep, { hash, chainId })
await action.isActionStepValid(actionStep, { hash, chainId, knownSignatures: allKnownSignatures })
).toBe(true);
});

Expand All @@ -706,6 +707,7 @@ describe("EventAction Func Selector", () => {
const criteriaMatch = await action.isActionStepValid(actionStep, {
hash,
chainId,
knownSignatures: allKnownSignatures
});

expect(criteriaMatch).toBe(true);
Expand All @@ -727,7 +729,7 @@ describe("EventAction Func Selector", () => {
});

try {
await action.isActionStepValid(invalidStep, { hash, chainId });
await action.isActionStepValid(invalidStep, { hash, chainId, knownSignatures: allKnownSignatures });
} catch (e) {
expect(e).toBeInstanceOf(Error);
expect((e as Error).message).toContain(
Expand All @@ -743,7 +745,7 @@ describe("EventAction Func Selector", () => {
value: parseEther(".1"),
});

expect(await action.validateActionSteps({ hash, chainId })).toBe(true);
expect(await action.validateActionSteps({ hash, chainId, knownSignatures: allKnownSignatures })).toBe(true);
})

test("validates against NOT_EQUAL filter criteria", async () => {
Expand All @@ -760,6 +762,7 @@ describe("EventAction Func Selector", () => {
await action.isActionStepValid(actionStep, {
hash,
chainId,
knownSignatures: allKnownSignatures
}),
).toBe(true);
});
Expand All @@ -784,6 +787,7 @@ describe("EventAction Func Selector", () => {
await action.isActionStepValid(actionStep, {
hash,
chainId,
knownSignatures: allKnownSignatures
}),
).toBe(true);
});
Expand All @@ -807,6 +811,7 @@ describe("EventAction Func Selector", () => {
await action.isActionStepValid(actionStep, {
hash,
chainId,
knownSignatures: allKnownSignatures
}),
).toBe(true);
});
Expand All @@ -822,6 +827,7 @@ describe("EventAction Func Selector", () => {
await action.validateActionSteps({
hash,
chainId,
knownSignatures: allKnownSignatures
}),
).toBe(true);
});
Expand Down
Loading

0 comments on commit 9860502

Please sign in to comment.