fix: redstone gateway plugin does not work with trailing slashes #66

This commit is contained in:
asiaziola
2021-12-27 08:44:08 +01:00
committed by Piotr Pędziwiatr
parent c43ded5d94
commit b287c443e7
4 changed files with 13 additions and 5 deletions

View File

@@ -27,8 +27,6 @@ const arweave = Arweave.init({
logging: false
});
const gatewayUrl = 'https://gateway.redstone.finance';
LoggerFactory.INST.logLevel('fatal');
const testCases: string[] = JSON.parse(
@@ -42,7 +40,7 @@ const testCases: string[] = JSON.parse(
describe.each([750000, 775000, 800000, 825000, 850000])('testing for block height %d', (toBlockHeight) => {
it('returns same amount of interactions for the same block height', async () => {
console.log('toBlockHeight', toBlockHeight);
const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader(gatewayUrl);
const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance/');
const arweaveInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave);
const responseRedstoneInteractionsLoader: GQLEdgeInterface[] = await redstoneInteractionsLoader.load(
'Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY',
@@ -62,7 +60,7 @@ describe.each([750000, 775000, 800000, 825000, 850000])('testing for block heigh
describe.each(testCases)('testing contractId %s', (contractTxId) => {
it('returns same interactions ids for RedstoneGatewayLoader and ArweaveGatewayInteractionsLoader', async () => {
const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader(gatewayUrl);
const redstoneInteractionsLoader = new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance');
const arweaveInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave);
const responseRedstoneInteractionsLoader: GQLEdgeInterface[] = await redstoneInteractionsLoader.load(
contractTxId,

View File

@@ -87,6 +87,11 @@ const fetchMock = jest
);
describe('RedstoneGatewayInteractionsLoader -> load', () => {
it('should be called with baseUrl devoid of trailing slashes', async () => {
const loader = new RedstoneGatewayInteractionsLoader('http://baseUrl/');
expect(loader['baseUrl']).toBe('http://baseUrl');
});
it('should return correct number of interactions', async () => {
const loader = new RedstoneGatewayInteractionsLoader('http://baseUrl');
const response: GQLEdgeInterface[] = await loader.load(contractId, fromBlockHeight, toBlockHeight);

View File

@@ -1,4 +1,4 @@
import { Benchmark, InteractionsLoader, LoggerFactory } from '@smartweave';
import { Benchmark, InteractionsLoader, LoggerFactory, stripTrailingSlash } from '@smartweave';
import { GQLEdgeInterface, GQLNodeInterface } from 'legacy/gqlResult';
import 'isomorphic-fetch';
interface Paging {
@@ -53,6 +53,7 @@ type ConfirmationStatus =
*/
export class RedstoneGatewayInteractionsLoader implements InteractionsLoader {
constructor(private readonly baseUrl: string, private readonly confirmationStatus: ConfirmationStatus = {}) {
this.baseUrl = stripTrailingSlash(baseUrl);
Object.assign(this, confirmationStatus);
}

View File

@@ -52,3 +52,7 @@ export function timeout(s: number): { timeoutId: number; timeoutPromise: Promise
timeoutPromise
};
}
export function stripTrailingSlash(str: string) {
return str.endsWith('/') ? str.slice(0, -1) : str;
}