Skip to content

Commit

Permalink
Reusing test condition objects from test-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
vzotova committed Jan 1, 2025
1 parent b24ba6a commit 5c72c19
Showing 1 changed file with 21 additions and 65 deletions.
86 changes: 21 additions & 65 deletions packages/taco/test/conditions/lingo.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { TEST_CHAIN_ID, TEST_ECDSA_PUBLIC_KEY } from '@nucypher/test-utils';
import { TEST_CHAIN_ID } from '@nucypher/test-utils';
import { describe, expect, it } from 'vitest';

import { ConditionExpression } from '../../src/conditions/condition-expr';
import {
testJsonApiConditionObj,
testJsonRpcConditionObj,
testJWTConditionObj,
testRpcConditionObj,
testTimeConditionObj,
} from '../test-utils';

describe('check that valid lingo in python is valid in typescript', () => {
const timeConditionProps = {
conditionType: 'time',
method: 'blocktime',
chain: TEST_CHAIN_ID,
returnValueTest: { value: 0, comparator: '>' },
};

const contractConditionProps = {
conditionType: 'contract',
chain: TEST_CHAIN_ID,
Expand All @@ -35,76 +35,32 @@ describe('check that valid lingo in python is valid in typescript', () => {
value: true,
},
};
const rpcConditionProps = {
conditionType: 'rpc',
chain: TEST_CHAIN_ID,
method: 'eth_getBalance',
parameters: ['0x3d2Bed3259b165EB02A7F0D0753e7a01912A68f8', 'latest'],
returnValueTest: {
comparator: '>=',
value: 10000000000000,
},
};
const jsonApiConditionProps = {
conditionType: 'json-api',
endpoint: 'https://api.example.com/data',
query: '$.store.book[0].price',
parameters: {
ids: 'ethereum',
vs_currencies: 'usd',
},
returnValueTest: {
comparator: '==',
value: 2,
},
};
const jsonRpcConditionProps = {
conditionType: 'json-rpc',
endpoint: 'https://math.example.com/',
method: 'subtract',
params: [42, 23],
query: '$.value',
returnValueTest: {
comparator: '==',
value: 2,
},
};
// TODO reuse similar object from test-utils
const jwtConditionProps = {
conditionType: 'jwt',
publicKey: TEST_ECDSA_PUBLIC_KEY,
expectedIssuer: '0xacbd',
subject: ':userAddress',
expirationWindow: 1800,
issuedWindow: 86400,
jwtToken: ':jwt',
};
const sequentialConditionProps = {
conditionType: 'sequential',
conditionVariables: [
{
varName: 'timeValue',
condition: timeConditionProps,
condition: testTimeConditionObj,
},
{
varName: 'rpcValue',
condition: rpcConditionProps,
condition: testRpcConditionObj,
},
{
varName: 'contractValue',
condition: contractConditionProps,
},
{
varName: 'jsonValue',
condition: jsonApiConditionProps,
condition: testJsonApiConditionObj,
},
],
};
const ifThenElseConditionProps = {
conditionType: 'if-then-else',
ifCondition: jsonRpcConditionProps,
thenCondition: jsonApiConditionProps,
elseCondition: timeConditionProps,
ifCondition: testJsonRpcConditionObj,
thenCondition: testJsonApiConditionObj,
elseCondition: testTimeConditionObj,
};

const compoundConditionProps = {
Expand All @@ -114,22 +70,22 @@ describe('check that valid lingo in python is valid in typescript', () => {
contractConditionProps,
ifThenElseConditionProps,
sequentialConditionProps,
rpcConditionProps,
testRpcConditionObj,
{
conditionType: 'compound',
operator: 'not',
operands: [timeConditionProps],
operands: [testTimeConditionObj],
},
],
};

it.each([
rpcConditionProps,
timeConditionProps,
testRpcConditionObj,
testTimeConditionObj,
contractConditionProps,
jsonApiConditionProps,
jsonRpcConditionProps,
jwtConditionProps,
testJsonApiConditionObj,
testJsonRpcConditionObj,
testJWTConditionObj,
compoundConditionProps,
sequentialConditionProps,
ifThenElseConditionProps,
Expand Down

0 comments on commit 5c72c19

Please sign in to comment.