Skip to content

Commit

Permalink
Update userAddressSchema to accomodate additional userAddress auth-sp…
Browse files Browse the repository at this point in the history
…ecific values.
  • Loading branch information
derekpierre committed May 30, 2024
1 parent 0ec1502 commit 14aaeb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/taco/src/conditions/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
CONTEXT_PARAM_PREFIX,
CONTEXT_PARAM_REGEXP,
ETH_ADDRESS_REGEXP,
USER_ADDRESS_PARAM_EIP712,
USER_ADDRESS_PARAM_EIP4361,
USER_ADDRESS_PARAM_DEFAULT,
} from './const';

Expand Down Expand Up @@ -36,7 +38,8 @@ export const returnValueTestSchema = z.object({
export type ReturnValueTestProps = z.infer<typeof returnValueTestSchema>;

const EthAddressSchema = z.string().regex(ETH_ADDRESS_REGEXP);
const UserAddressSchema = z.literal(USER_ADDRESS_PARAM_DEFAULT);

const UserAddressSchema = z.enum([USER_ADDRESS_PARAM_EIP712, USER_ADDRESS_PARAM_EIP4361, USER_ADDRESS_PARAM_DEFAULT]);
export const EthAddressOrUserAddressSchema = z.union([
EthAddressSchema,
UserAddressSchema,
Expand Down
20 changes: 19 additions & 1 deletion packages/taco/test/conditions/base/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
FunctionAbiProps,
} from '../../../src/conditions/base/contract';
import { ConditionExpression } from '../../../src/conditions/condition-expr';
import { USER_ADDRESS_PARAM_DEFAULT } from '../../../src/conditions/const';
import { USER_ADDRESS_PARAMS, USER_ADDRESS_PARAM_DEFAULT } from '../../../src/conditions/const';
import { CustomContextParam } from '../../../src/conditions/context';
import { testContractConditionObj, testFunctionAbi } from '../../test-utils';

Expand Down Expand Up @@ -150,6 +150,24 @@ describe('accepts either standardContractType or functionAbi but not both or non
});
});

describe('supports various user address params', () => {
it.each(
USER_ADDRESS_PARAMS
)("handles different user address context params", (userAddressContextParam) => {
const contractConditionObj: ContractConditionProps = {
...testContractConditionObj,
parameters: [userAddressContextParam],
}

const result = ContractCondition.validate(
contractConditionSchema,
contractConditionObj,
);

expect(result.error).toBeUndefined();
});
});

describe('supports custom function abi', () => {
const contractConditionObj: ContractConditionProps = {
...testContractConditionObj,
Expand Down

0 comments on commit 14aaeb9

Please sign in to comment.