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

Ruleset Unit Tests and tweaks #445

Merged
merged 16 commits into from
Sep 13, 2023
Merged

Ruleset Unit Tests and tweaks #445

merged 16 commits into from
Sep 13, 2023

Conversation

panieldark
Copy link
Contributor

@panieldark panieldark commented Sep 12, 2023

Motivation

RuleSet work needs tests, what currently exists are only scripts

Solution

Adds tests, also tweaks a couple things about how RuleSets are defined

Proof

PR Checklist

  • added tests
  • updated documentation
  • added changeset if necessary
  • tested in dev/testnet
  • tested site with snap (we haven't automated this yet)
  • re-built & tested circuits if any of them changed
  • updated contracts storage layout (if contracts were updated)

@changeset-bot
Copy link

changeset-bot bot commented Sep 12, 2023

🦋 Changeset detected

Latest commit: fb0810f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nocturne-xyz/deposit-screener Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@panieldark panieldark force-pushed the rulesets-tests-and-tweaks branch from c8dd157 to 2b2b783 Compare September 12, 2023 23:31
| (typeof REJECT_ADDRESSES)[keyof typeof REJECT_ADDRESSES]
| (typeof APPROVE_ADDRESSES)[keyof typeof APPROVE_ADDRESSES];

const MOCK_API_CALLS = apiCallsSnapshot as Record<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you guys hate these types, but it allows RuleSet.check() to allow for looser types being imported from json (ex: we recognize riskType with strict types, riskType: "COUNTERPARTY" | "OWNERSHIP" | "INDIRECT", but from json, riskType is typed as string, and thus it gives a TypeError, without these types

Copy link
Contributor

@luketchang luketchang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments for now + Slack comments

return partial.threshold(data);
})
);
const shouldApplyRule = results[this.predicateFn]((_) => _);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need ((_) => _)? Can we not just say results[this.predicateFn]()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do; the predicate fns require a fn to predicate off of, and unfortunately in TypeScript there isn't cleaner syntactic sugar

async check(deposit: ScreeningDepositRequest): Promise<Rejection | Delay> {
async check(
deposit: ScreeningDepositRequest,
cache: Partial<Record<ApiCallKeys, CallReturnData>> = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we alias the cache type? The really long types are unweildy, aliases would at least help a little bit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, changed

): Promise<MisttrackAddressOverviewData> => {
const token = "ETH";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up (no action item rn), we may have to screen on more than one chain because sometimes if hack happens on optimism and is bridged back to ETH, the ETH screening call doesn't always show the hack. Made ticket

TC_7: "0xadd7885af8f37df5c965e5d16caf16f807dc79a0",
} as const;

export const APPROVE_ADDRESSES = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ishaan is a good example to keep in here, he's a normal defi user but somehow gets flagged by TRM for stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, what is his address? I'll add him in a later PR addressing the tickets you made

actors/deposit-screener/test/RULESET_V1.test.ts Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
@panieldark panieldark enabled auto-merge (squash) September 13, 2023 20:53
Copy link
Contributor

@luketchang luketchang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, lgtm. Bit easier to read now 👍

@panieldark panieldark merged commit 016af4b into main Sep 13, 2023
2 checks passed
@panieldark panieldark deleted the rulesets-tests-and-tweaks branch September 13, 2023 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants