feat: simplified configuration for redstone gateway
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
7fe41f6516
commit
bb62c91e16
@@ -92,7 +92,7 @@ In order to use the [Redstone Gateway](https://github.com/redstone-finance/redst
|
||||
configure the smartweave instance in the following way:
|
||||
```ts
|
||||
const smartweave = SmartWeaveNodeFactory.memCachedBased(arweave)
|
||||
.setInteractionsLoader(new RedstoneGatewayInteractionsLoader(gatewayUrl))
|
||||
.useRedStoneGateway()
|
||||
.build();
|
||||
```
|
||||
The gateway is currently available under [https://gateway.redstone.finance](https://gateway.redstone.finance) url.
|
||||
@@ -104,7 +104,7 @@ all the interactions. There is a risk of returning [corrupted transactions](http
|
||||
2. `{confirmed: true}` - returns only confirmed transactions - the most safe mode, eg:
|
||||
```ts
|
||||
const smartweave = SmartWeaveNodeFactory.memCachedBased(arweave)
|
||||
.setInteractionsLoader(new RedstoneGatewayInteractionsLoader(gatewayUrl, {confirmed: true}))
|
||||
.useRedStoneGateway( {confirmed: true} )
|
||||
.build();
|
||||
```
|
||||
|
||||
@@ -112,7 +112,7 @@ const smartweave = SmartWeaveNodeFactory.memCachedBased(arweave)
|
||||
Not as safe as previous mode, but good if you want combine high level of safety with the most recent data.
|
||||
```ts
|
||||
const smartweave = SmartWeaveNodeFactory.memCachedBased(arweave)
|
||||
.setInteractionsLoader(new RedstoneGatewayInteractionsLoader(gatewayUrl, {notCorrupted: true}))
|
||||
.useRedStoneGateway( {notCorrupted: true} )
|
||||
.build();
|
||||
```
|
||||
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
/* eslint-disable */
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { interactRead, readContract } from 'smartweave';
|
||||
import {interactRead, readContract} from 'smartweave';
|
||||
import Arweave from 'arweave';
|
||||
import {
|
||||
LoggerFactory,
|
||||
MemCache,
|
||||
RedstoneGatewayContractDefinitionLoader,
|
||||
RedstoneGatewayInteractionsLoader,
|
||||
SmartWeaveNodeFactory,
|
||||
SmartWeaveWebFactory,
|
||||
SourceType
|
||||
LoggerFactory,
|
||||
MemCache,
|
||||
RedstoneGatewayContractDefinitionLoader,
|
||||
RedstoneGatewayInteractionsLoader,
|
||||
SmartWeaveNodeFactory,
|
||||
SmartWeaveWebFactory,
|
||||
SourceType
|
||||
} from '@smartweave';
|
||||
|
||||
const stringify = require('safe-stable-stringify');
|
||||
|
||||
function* chunks(arr, n) {
|
||||
for (let i = 0; i < arr.length; i += n) {
|
||||
// note: wrapping with an array to make it compatible with describe.each
|
||||
yield [arr.slice(i, i + n)];
|
||||
}
|
||||
for (let i = 0; i < arr.length; i += n) {
|
||||
// note: wrapping with an array to make it compatible with describe.each
|
||||
yield [arr.slice(i, i + n)];
|
||||
}
|
||||
}
|
||||
|
||||
const arweave = Arweave.init({
|
||||
host: 'arweave.net',
|
||||
port: 443,
|
||||
protocol: 'https',
|
||||
timeout: 30000,
|
||||
logging: false
|
||||
host: 'arweave.net',
|
||||
port: 443,
|
||||
protocol: 'https',
|
||||
timeout: 30000,
|
||||
logging: false
|
||||
});
|
||||
|
||||
LoggerFactory.INST.logLevel('fatal');
|
||||
@@ -39,107 +39,90 @@ const chunked: string[][][] = [...chunks(testCases, 10)];
|
||||
const chunkedGw: string[][][] = [...chunks(testCasesGw, 10)];
|
||||
|
||||
describe.each(chunked)('v1 compare.suite %#', (contracts: string[]) => {
|
||||
// note: concurrent doesn't seem to be working here, duh...
|
||||
// will probably need to manually split all the test cases to separate test files
|
||||
it.concurrent.each(contracts)(
|
||||
'.test %# %o',
|
||||
async (contractTxId: string) => {
|
||||
const blockHeight = 850127;
|
||||
console.log('readContract', contractTxId);
|
||||
const resultString = fs
|
||||
.readFileSync(path.join(__dirname, 'test-cases', 'contracts', `${contractTxId}.json`), 'utf-8')
|
||||
.trim();
|
||||
console.log('readState', contractTxId);
|
||||
const result2 = await SmartWeaveNodeFactory.memCachedBased(arweave, 1)
|
||||
.setInteractionsLoader(
|
||||
new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance', null, SourceType.ARWEAVE)
|
||||
)
|
||||
.build()
|
||||
.contract(contractTxId)
|
||||
.setEvaluationOptions({
|
||||
useFastCopy: true
|
||||
})
|
||||
.readState(blockHeight);
|
||||
const result2String = stringify(result2.state).trim();
|
||||
expect(result2String).toEqual(resultString);
|
||||
},
|
||||
800000
|
||||
);
|
||||
// note: concurrent doesn't seem to be working here, duh...
|
||||
// will probably need to manually split all the test cases to separate test files
|
||||
it.concurrent.each(contracts)(
|
||||
'.test %# %o',
|
||||
async (contractTxId: string) => {
|
||||
const blockHeight = 850127;
|
||||
console.log('readContract', contractTxId);
|
||||
const resultString = fs
|
||||
.readFileSync(path.join(__dirname, 'test-cases', 'contracts', `${contractTxId}.json`), 'utf-8')
|
||||
.trim();
|
||||
console.log('readState', contractTxId);
|
||||
const result2 = await SmartWeaveNodeFactory.memCachedBased(arweave, 1)
|
||||
.useRedStoneGateway(null, SourceType.ARWEAVE)
|
||||
.build()
|
||||
.contract(contractTxId)
|
||||
.setEvaluationOptions({
|
||||
useFastCopy: true
|
||||
})
|
||||
.readState(blockHeight);
|
||||
const result2String = stringify(result2.state).trim();
|
||||
expect(result2String).toEqual(resultString);
|
||||
},
|
||||
800000
|
||||
);
|
||||
});
|
||||
|
||||
fdescribe.each(chunkedGw)('gateways compare.suite %#', (contracts: string[]) => {
|
||||
// note: concurrent doesn't seem to be working here, duh...
|
||||
// will probably need to manually split all the test cases to separate test files
|
||||
it.concurrent.each(contracts)(
|
||||
'.test %# %o',
|
||||
async (contractTxId: string) => {
|
||||
const blockHeight = 855134;
|
||||
console.log('readState Redstone Gateway', contractTxId);
|
||||
const smartweaveR = SmartWeaveWebFactory.memCachedBased(arweave, 1)
|
||||
.setInteractionsLoader(
|
||||
new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance', null, SourceType.ARWEAVE)
|
||||
)
|
||||
.setDefinitionLoader(
|
||||
new RedstoneGatewayContractDefinitionLoader('https://gateway.redstone.finance', arweave, new MemCache())
|
||||
)
|
||||
.build();
|
||||
const result = await smartweaveR.contract(contractTxId).readState(blockHeight);
|
||||
const resultString = stringify(result.state).trim();
|
||||
// note: concurrent doesn't seem to be working here, duh...
|
||||
// will probably need to manually split all the test cases to separate test files
|
||||
it.concurrent.each(contracts)(
|
||||
'.test %# %o',
|
||||
async (contractTxId: string) => {
|
||||
const blockHeight = 855134;
|
||||
console.log('readState Redstone Gateway', contractTxId);
|
||||
const smartweaveR = SmartWeaveWebFactory.memCachedBased(arweave, 1)
|
||||
.useRedStoneGateway(null, SourceType.ARWEAVE)
|
||||
.build();
|
||||
const result = await smartweaveR.contract(contractTxId).readState(blockHeight);
|
||||
const resultString = stringify(result.state).trim();
|
||||
|
||||
console.log('readState Arweave Gateway', contractTxId);
|
||||
const result2 = await SmartWeaveNodeFactory.memCached(arweave, 1).contract(contractTxId).readState(blockHeight);
|
||||
const result2String = stringify(result2.state).trim();
|
||||
expect(result2String).toEqual(resultString);
|
||||
},
|
||||
800000
|
||||
);
|
||||
console.log('readState Arweave Gateway', contractTxId);
|
||||
const result2 = await SmartWeaveNodeFactory.memCached(arweave, 1).contract(contractTxId).readState(blockHeight);
|
||||
const result2String = stringify(result2.state).trim();
|
||||
expect(result2String).toEqual(resultString);
|
||||
},
|
||||
800000
|
||||
);
|
||||
});
|
||||
|
||||
describe('readState', () => {
|
||||
it('should properly read state at requested block height', async () => {
|
||||
const contractTxId = 'CbGCxBJn6jLeezqDl1w3o8oCSeRCb-MmtZNKPodla-0';
|
||||
const blockHeight = 707892;
|
||||
const result = await readContract(arweave, contractTxId, blockHeight);
|
||||
const resultString = stringify(result).trim();
|
||||
it('should properly read state at requested block height', async () => {
|
||||
const contractTxId = 'CbGCxBJn6jLeezqDl1w3o8oCSeRCb-MmtZNKPodla-0';
|
||||
const blockHeight = 707892;
|
||||
const result = await readContract(arweave, contractTxId, blockHeight);
|
||||
const resultString = stringify(result).trim();
|
||||
|
||||
const result2 = await SmartWeaveNodeFactory.memCachedBased(arweave, 1)
|
||||
.setInteractionsLoader(
|
||||
new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance', null, SourceType.ARWEAVE)
|
||||
)
|
||||
.setDefinitionLoader(
|
||||
new RedstoneGatewayContractDefinitionLoader('https://gateway.redstone.finance', arweave, new MemCache())
|
||||
)
|
||||
.build()
|
||||
.contract(contractTxId)
|
||||
.readState(blockHeight);
|
||||
const result2String = stringify(result2.state).trim();
|
||||
const result2 = await SmartWeaveNodeFactory.memCachedBased(arweave, 1)
|
||||
.useRedStoneGateway(null, SourceType.ARWEAVE)
|
||||
.build()
|
||||
.contract(contractTxId)
|
||||
.readState(blockHeight);
|
||||
const result2String = stringify(result2.state).trim();
|
||||
|
||||
expect(result2String).toEqual(resultString);
|
||||
}, 800000);
|
||||
expect(result2String).toEqual(resultString);
|
||||
}, 800000);
|
||||
|
||||
it('should properly check balance of a PST contract', async () => {
|
||||
const jwk = await arweave.wallets.generate();
|
||||
const contractTxId = '-8A6RexFkpfWwuyVO98wzSFZh0d6VJuI-buTJvlwOJQ';
|
||||
const v1Result = await interactRead(arweave, jwk, contractTxId, {
|
||||
function: 'balance',
|
||||
target: '6Z-ifqgVi1jOwMvSNwKWs6ewUEQ0gU9eo4aHYC3rN1M'
|
||||
});
|
||||
it('should properly check balance of a PST contract', async () => {
|
||||
const jwk = await arweave.wallets.generate();
|
||||
const contractTxId = '-8A6RexFkpfWwuyVO98wzSFZh0d6VJuI-buTJvlwOJQ';
|
||||
const v1Result = await interactRead(arweave, jwk, contractTxId, {
|
||||
function: 'balance',
|
||||
target: '6Z-ifqgVi1jOwMvSNwKWs6ewUEQ0gU9eo4aHYC3rN1M'
|
||||
});
|
||||
|
||||
const v2Result = await SmartWeaveNodeFactory.memCachedBased(arweave, 1)
|
||||
.setInteractionsLoader(
|
||||
new RedstoneGatewayInteractionsLoader('https://gateway.redstone.finance', null, SourceType.ARWEAVE)
|
||||
)
|
||||
.setDefinitionLoader(
|
||||
new RedstoneGatewayContractDefinitionLoader('https://gateway.redstone.finance', arweave, new MemCache())
|
||||
)
|
||||
.build()
|
||||
.contract(contractTxId)
|
||||
.connect(jwk)
|
||||
.viewState({
|
||||
function: 'balance',
|
||||
target: '6Z-ifqgVi1jOwMvSNwKWs6ewUEQ0gU9eo4aHYC3rN1M'
|
||||
});
|
||||
const v2Result = await SmartWeaveNodeFactory.memCachedBased(arweave, 1)
|
||||
.useRedStoneGateway(null, SourceType.ARWEAVE)
|
||||
.build()
|
||||
.contract(contractTxId)
|
||||
.connect(jwk)
|
||||
.viewState({
|
||||
function: 'balance',
|
||||
target: '6Z-ifqgVi1jOwMvSNwKWs6ewUEQ0gU9eo4aHYC3rN1M'
|
||||
});
|
||||
|
||||
expect(v1Result).toEqual(v2Result.result);
|
||||
}, 800000);
|
||||
expect(v1Result).toEqual(v2Result.result);
|
||||
}, 800000);
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ export interface RedstoneGatewayInteractions {
|
||||
message?: string;
|
||||
}
|
||||
|
||||
type ConfirmationStatus =
|
||||
export type ConfirmationStatus =
|
||||
| {
|
||||
notCorrupted?: boolean;
|
||||
confirmed?: null;
|
||||
|
||||
Reference in New Issue
Block a user