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

Refactor packages APIs #301

Merged
merged 24 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b58152c
chore(examples): add a nextjs example
piotr-roslaniec Sep 21, 2023
b8bb41b
chore(refactor): refactor package tests
piotr-roslaniec Sep 22, 2023
2e6740e
chore(refactor): refactor taco package internals from character based…
piotr-roslaniec Sep 22, 2023
5927d78
chore(refactor): divide shared package into pre and taco
piotr-roslaniec Sep 22, 2023
a5e6d8b
chore(examples): add taco examples
piotr-roslaniec Sep 25, 2023
da71bf0
chore(test): add multichain condition tests
piotr-roslaniec Sep 26, 2023
7de1be7
chore(deps): deprecate support for node 16
piotr-roslaniec Sep 26, 2023
58254d0
chore: fix vitest test config
piotr-roslaniec Sep 27, 2023
737b215
feat(alpha-13): update coordinator contract
piotr-roslaniec Sep 29, 2023
71b3089
feat(alpha-13): check authorization before encrypting
piotr-roslaniec Sep 29, 2023
2aa2720
chore(examples): update taco/nodejs example
piotr-roslaniec Sep 29, 2023
1292f31
chore(demos): add demos/taco-demo
piotr-roslaniec Sep 29, 2023
5051b03
chore(examples): update examples for alpha-13
piotr-roslaniec Sep 29, 2023
a417a00
chore: remove redundant lockfile
piotr-roslaniec Oct 2, 2023
ed40754
chore: document legacy demos
piotr-roslaniec Oct 2, 2023
719f6a0
chore(demos): add demos/taco-nft-demo
piotr-roslaniec Oct 3, 2023
f3fc336
feat!: deprecate pre-tdec
piotr-roslaniec Oct 4, 2023
7752c24
Update examples/README.md
piotr-roslaniec Oct 5, 2023
9042753
Update examples/taco/webpack-5/src/index.html
piotr-roslaniec Oct 5, 2023
d5c70a5
Update demos/taco-demo/README.md
piotr-roslaniec Oct 5, 2023
acb0fa1
fix(test): fix pre tests after a bad rebase
piotr-roslaniec Oct 6, 2023
fbc90e1
feature(demos): add ritual id input to demos
piotr-roslaniec Oct 6, 2023
d2c4bf7
fix(conditions): rpc condition parameters not checking length
piotr-roslaniec Oct 6, 2023
0a13562
feature(allowlist): expose a method to check encrypter authorization
piotr-roslaniec Oct 6, 2023
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
8 changes: 5 additions & 3 deletions packages/taco/src/conditions/base/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export const rpcConditionSchema = z.object({
conditionType: z.literal(RpcConditionType).default(RpcConditionType),
chain: createUnionSchema(SUPPORTED_CHAIN_IDS),
method: z.enum(['eth_getBalance', 'balanceOf']),
parameters: z.array(
z.union([EthAddressOrUserAddressSchema, z.string(), z.number()]),
),
parameters: z.union([
z.array(EthAddressOrUserAddressSchema).length(1),
// Using tuple here because ordering matters
z.tuple([EthAddressOrUserAddressSchema, z.union([z.string(), z.number()])]),
Copy link
Member

Choose a reason for hiding this comment

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

Great - 🚀

]),
returnValueTest: returnValueTestSchema,
});

Expand Down
49 changes: 49 additions & 0 deletions packages/taco/test/conditions/base/rpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TEST_CONTRACT_ADDR } from '@nucypher/test-utils';
import { describe, expect, it } from 'vitest';

import { RpcCondition } from '../../../src/conditions';
Expand Down Expand Up @@ -34,4 +35,52 @@ describe('validation', () => {
},
});
});

describe('parameters', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Love the testing!

it('accepts a single address', () => {
const result = RpcCondition.validate(rpcConditionSchema, {
...testRpcConditionObj,
parameters: [TEST_CONTRACT_ADDR],
});

expect(result.error).toBeUndefined();
expect(result.data).toEqual({
...testRpcConditionObj,
parameters: [TEST_CONTRACT_ADDR],
});
});

it('accepts a single address and a block number', () => {
const result = RpcCondition.validate(rpcConditionSchema, {
...testRpcConditionObj,
parameters: [TEST_CONTRACT_ADDR, 'latest'],
});

expect(result.error).toBeUndefined();
expect(result.data).toEqual({
...testRpcConditionObj,
parameters: [TEST_CONTRACT_ADDR, 'latest'],
});
});

it('rejects on an extra parameter', () => {
const result = RpcCondition.validate(rpcConditionSchema, {
...testRpcConditionObj,
parameters: [
TEST_CONTRACT_ADDR,
'latest',
// Intentionally adding a third, invalid parameter
'0x1234',
],
});

expect(result.error).toBeDefined();
expect(result.data).toBeUndefined();
expect(result.error?.format()).toMatchObject({
parameters: {
_errors: ['Array must contain exactly 1 element(s)'],
},
});
});
});
});