Skip to content

Commit

Permalink
apply pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Nov 15, 2023
1 parent e00382e commit d65ba98
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/taco/test/conditions/base/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('validation', () => {
it('rejects empty parameters', () => {
const rpcObj = {
...testRpcConditionObj,
parameters: [],
parameters: [], // Update this after updating available RPC methods
};

const result = RpcCondition.validate(rpcConditionSchema, rpcObj);
Expand Down
63 changes: 47 additions & 16 deletions packages/taco/test/conditions/compound-condition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
TimeCondition,
} from '../../src/conditions';
import {
compoundConditionSchema,
CompoundConditionType,
compoundConditionSchema,
} from '../../src/conditions/compound-condition';
import {
testContractConditionObj,
Expand Down Expand Up @@ -225,27 +225,58 @@ describe('validation', () => {
expect(() => new CompoundCondition(badObj)).toThrow();
});

it('rejects empty operands', () => {
const badObj = {
operator: 'and',
operands: [],
};
expect(() => new CompoundCondition(badObj)).toThrow();
});
it.each(['or', 'and'])(
'rejects empty operands for "%s" operator',
(operator) => {
const badObj = {
operator,
operands: [],
};
expect(() => new CompoundCondition(badObj)).toThrow();
},
);

it('rejects non-array operands for "and" and "or" operators', () => {
const badObj = {
operator: 'and',
operands: testContractConditionObj,
};
expect(() => new CompoundCondition(badObj)).toThrow();
});
it.each(['or', 'and'])(
'rejects non-array operands for "%s" operator',
(operator) => {
const badObj = {
operator,
operands: testContractConditionObj,
};
expect(() => new CompoundCondition(badObj)).toThrow();
},
);

it('rejects array operands for "not" operator', () => {
it('rejects array operands with non-one length for "not" operator', () => {
const badObj = {
operator: 'not',
operands: [testContractConditionObj, testTimeConditionObj],
};
expect(() => new CompoundCondition(badObj)).toThrow();
});

it.each(['or', 'and'])(
'accepts array operands for "%s" operator',
(operator) => {
const obj = {
operator,
operands: [testContractConditionObj, testTimeConditionObj],
};
expect(new CompoundCondition(obj).toObj()).toEqual({
conditionType: CompoundConditionType,
...obj,
});
},
);

it.each(['or', 'and'])(
'rejects array operands with non-greater-than-one length for "%s" operator',
(operator) => {
const badObj = {
operator,
operands: [testContractConditionObj],
};
expect(() => new CompoundCondition(badObj)).toThrow();
},
);
});
4 changes: 0 additions & 4 deletions packages/taco/test/conditions/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ describe('param or context param schema', () => {
expect(paramOrContextParamSchema.safeParse(123.4).success).toBe(true);
});

it('accepts a hex string', () => {
expect(paramOrContextParamSchema.safeParse('deadbeef').success).toBe(true);
});

it('accepts a 0x-prefixed hex string', () => {
expect(paramOrContextParamSchema.safeParse('0xdeadbeef').success).toBe(
true,
Expand Down
4 changes: 2 additions & 2 deletions packages/taco/test/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import {
zip,
} from '@nucypher/shared';
import {
TEST_CHAIN_ID,
TEST_CONTRACT_ADDR,
fakeDkgFlow,
fakeSigner,
fakeTDecFlow,
TEST_CHAIN_ID,
TEST_CONTRACT_ADDR,
} from '@nucypher/test-utils';
import { SpyInstance, vi } from 'vitest';

Expand Down

0 comments on commit d65ba98

Please sign in to comment.