Skip to content

Commit

Permalink
Add lingo test to ensure that dictionaries used in `nucypher/nucypher…
Browse files Browse the repository at this point in the history
…` (nodes) are also valid in `taco-web` (client library).
  • Loading branch information
derekpierre committed Oct 15, 2024
1 parent 8819889 commit bda7227
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions packages/taco/test/conditions/lingo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { TEST_CHAIN_ID } from '@nucypher/test-utils';
import { describe, expect, it } from 'vitest';

import { ConditionExpression } from '../../src/conditions/condition-expr';

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,
method: 'isPolicyActive',
parameters: [':hrac'],
contractAddress: '0xA1bd3630a13D54EDF7320412B5C9F289230D260d',
functionAbi: {
type: 'function',
name: 'isPolicyActive',
stateMutability: 'view',
inputs: [
{
name: '_policyID',
type: 'bytes16',
internalType: 'bytes16',
},
],
outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
},
returnValueTest: {
comparator: '==',
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 sequentialConditionProps = {
conditionType: 'sequential',
conditionVariables: [
{
varName: 'timeValue',
condition: timeConditionProps,
},
{
varName: 'rpcValue',
condition: rpcConditionProps,
},
{
varName: 'contractValue',
condition: contractConditionProps,
},
{
varName: 'jsonValue',
condition: jsonApiConditionProps,
},
],
};
const ifThenElseConditionProps = {
conditionType: 'if-then-else',
ifCondition: rpcConditionProps,
thenCondition: jsonApiConditionProps,
elseCondition: timeConditionProps,
};

const compoundConditionProps = {
conditionType: 'compound',
operator: 'and',
operands: [
contractConditionProps,
ifThenElseConditionProps,
sequentialConditionProps,
rpcConditionProps,
{
conditionType: 'compound',
operator: 'not',
operands: [timeConditionProps],
},
],
};

it.each([
rpcConditionProps,
timeConditionProps,
contractConditionProps,
jsonApiConditionProps,
compoundConditionProps,
sequentialConditionProps,
ifThenElseConditionProps,
])('parsing of all condition types', (conditionProps) => {
const conditionExpr = {
version: ConditionExpression.version,
condition: conditionProps,
};
const condition = ConditionExpression.fromObj(conditionExpr);
expect(condition.toObj()).toBeDefined();
});
});

0 comments on commit bda7227

Please sign in to comment.