Skip to content

Commit

Permalink
fix(tests): update gateways test
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Mar 5, 2024
1 parent ae890c8 commit 1fcb3e6
Showing 1 changed file with 41 additions and 48 deletions.
89 changes: 41 additions & 48 deletions tests/arns-remote-cache/gateways.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { ArNSRemoteCache } from '../../src/common/caches/arns-remote-cache.js';
import { NotFound } from '../../src/common/error.js';
import { ARNS_DEVNET_REGISTRY_TX } from '../../src/constants.js';
import { SmartWeaveSortKey } from '../../src/utils/index.js';

describe('ArNSRemoteCache ~ GATEWAYS', () => {
const remoteCacheProvider = new ArNSRemoteCache({
contractTxId: ARNS_DEVNET_REGISTRY_TX,
});
const address = '1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo';
const currentBlockHeight = 1377100;
const previousBlockHeight = currentBlockHeight + 100;
const currentSortKey = new SmartWeaveSortKey(
'000001376946,0000000000000,18d52956c8e13ae1f557b4e67f6f298b8ffd2a5cd96e42ec24ca649b7401510f',
);

// gateway tests
it('should be able to fetch gateways', async () => {
const gateways = await remoteCacheProvider.getGateways();
Expand All @@ -21,56 +29,41 @@ describe('ArNSRemoteCache ~ GATEWAYS', () => {
expect(error).toBeInstanceOf(NotFound);
});

// TODO: add blockheight and sortkey tests when simulation with docker is added. current devnet contract doesnt have read api available at last interaction points to test.
// it('should return gateway state at a given block height', async () => {
// const blockHeight = 1348901;
// const address = '1H7WZIWhzwTH9FIcnuMqYkTsoyv1OTfGa_amvuYwrgo';
// const currentStake = 95048;
// const stakeIncrease = 51250;
// const gateway = await remoteCacheProvider.getGateway({
// address,
// evaluationParameters: { evalTo: { blockHeight } },
// });
// expect(gateway.operatorStake).toEqual(currentStake);
it('should return gateway state at a given block height', async () => {
const gateway = await remoteCacheProvider.getGateway({
address,
evaluationParameters: { evalTo: { blockHeight: currentBlockHeight } },
});

// const previousGatewayState = await remoteCacheProvider
// .getGateway({
// address,
// evaluationParameters: { evalTo: { blockHeight: blockHeight - 1 } },
// })
// .catch((e) => e);
// expect(previousGatewayState.operatorStake).toEqual(currentStake - stakeIncrease);
// });
const previousGatewayState = await remoteCacheProvider.getGateway({
address,
evaluationParameters: { evalTo: { blockHeight: previousBlockHeight } },
});
expect(
previousGatewayState.weights.tenureWeight ===
gateway.weights.tenureWeight,
).toBe(false);
});

// it('should return gateway state at a given sort key', async () => {
// const sortKey = new SmartWeaveSortKey(
// '000001372179,0000000000000,1babf113056ce4d158c06f17ac8a1d0bff603dd6218dad98381d8e6d295f50a5',
// );
// const address = 'usOg4jFzqinXK_ExoU5NijjEyggNA255998LNiM8Vtc';
// const gateway = await remoteCacheProvider.getGateway({
// address,
// evaluationParameters: { evalTo: { sortKey: sortKey.toString() } },
// });
// expect(gateway).toBeDefined();
// });
it('should return gateway state at a given sort key', async () => {
const gateway = await remoteCacheProvider.getGateway({
address,
evaluationParameters: { evalTo: { sortKey: currentSortKey.toString() } },
});
expect(gateway).toBeDefined();
});

// it('should return gateways state at a given block height', async () => {
// const blockHeight = 1372179;
// const address = 'usOg4jFzqinXK_ExoU5NijjEyggNA255998LNiM8Vtc';
// const gateways = await remoteCacheProvider.getGateways({
// evaluationParameters: { evalTo: { blockHeight } },
// });
// expect(gateways[address]).toBeDefined();
// });
it('should return gateways state at a given block height', async () => {
const gateways = await remoteCacheProvider.getGateways({
evaluationParameters: { evalTo: { blockHeight: currentBlockHeight } },
});
expect(gateways[address]).toBeDefined();
});

// it('should return gateways state at a given sort key', async () => {
// const address = 'usOg4jFzqinXK_ExoU5NijjEyggNA255998LNiM8Vtc';
// const sortKey = new SmartWeaveSortKey(
// '000001372179,0000000000000,1babf113056ce4d158c06f17ac8a1d0bff603dd6218dad98381d8e6d295f50a5',
// );
// const gateways = await remoteCacheProvider.getGateways({
// evaluationParameters: { evalTo: { sortKey: sortKey.toString() } },
// });
// expect(gateways[address]).toBeDefined();
// });
it('should return gateways state at a given sort key', async () => {
const gateways = await remoteCacheProvider.getGateways({
evaluationParameters: { evalTo: { sortKey: currentSortKey.toString() } },
});
expect(gateways[address]).toBeDefined();
});
});

0 comments on commit 1fcb3e6

Please sign in to comment.