Skip to content

Commit

Permalink
fix(types and tests): update evalTo to allow undefined sortKey and bl…
Browse files Browse the repository at this point in the history
…ock and test that
  • Loading branch information
Atticus committed Mar 22, 2024
1 parent 2867abc commit a59f05c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function isContractTxIdConfiguration(
}

export type EvaluationOptions = {
evalTo?: { sortKey: SortKey } | { blockHeight: BlockHeight };
evalTo?: { sortKey?: SortKey } | { blockHeight?: BlockHeight };
// TODO: any other evaluation constraints
};

Expand Down
2 changes: 1 addition & 1 deletion src/common/contracts/warp-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class WarpContract<T> implements BaseContract<T>, ReadContract {
let sortKeyOrBlockHeight: string | number | undefined;
if (evalTo && 'sortKey' in evalTo) {
sortKeyOrBlockHeight = evalTo.sortKey;
} else if (evalTo && 'blockHeight') {
} else if (evalTo && 'blockHeight' in evalTo) {
sortKeyOrBlockHeight = evalTo.blockHeight;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/ant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ describe('ANT contract apis', () => {
});

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get contract state with evaluation options: ${JSON.stringify('%s')}`,
Expand All @@ -52,7 +54,9 @@ describe('ANT contract apis', () => {
);

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(`should get record: ${JSON.stringify('%s')}`, async (evalTo) => {
const record = await ant.getRecord({
Expand All @@ -63,7 +67,9 @@ describe('ANT contract apis', () => {
});

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get records with evaluation options: ${JSON.stringify('%s')}`,
Expand All @@ -74,7 +80,9 @@ describe('ANT contract apis', () => {
);

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get owner with evaluation options: ${JSON.stringify('%s')}`,
Expand All @@ -85,7 +93,9 @@ describe('ANT contract apis', () => {
);

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get controllers with evaluation options: ${JSON.stringify('%s')}`,
Expand All @@ -98,7 +108,9 @@ describe('ANT contract apis', () => {
);

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get name with evaluation options: ${JSON.stringify('%s')}`,
Expand All @@ -109,7 +121,9 @@ describe('ANT contract apis', () => {
);

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get ticker with evaluation options: ${JSON.stringify('%s')}`,
Expand All @@ -120,7 +134,9 @@ describe('ANT contract apis', () => {
);

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get balances with evaluation options: ${JSON.stringify('%s')}`,
Expand All @@ -131,7 +147,9 @@ describe('ANT contract apis', () => {
);

it.each([
[{ sortKey: undefined }],
[{ sortKey: evaluateToSortKey.toString() }],
[{ blockHeight: undefined }],
[{ blockHeight: evaluateToBlockHeight }],
])(
`should get balance with evaluation options: ${JSON.stringify('%s')}`,
Expand Down

0 comments on commit a59f05c

Please sign in to comment.