fix: redstone gateway plugin does not work with trailing slashes #66
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
c43ded5d94
commit
b287c443e7
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user