diff --git a/src/__tests__/integration/basic/complicated-contract.test.ts b/src/__tests__/integration/basic/complicated-contract.test.ts index c2b1877..01db86a 100644 --- a/src/__tests__/integration/basic/complicated-contract.test.ts +++ b/src/__tests__/integration/basic/complicated-contract.test.ts @@ -32,7 +32,7 @@ describe('Testing the SmartWeave client', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/basic/deploy-write-read.test.ts b/src/__tests__/integration/basic/deploy-write-read.test.ts index 4f3e57d..9d6118e 100644 --- a/src/__tests__/integration/basic/deploy-write-read.test.ts +++ b/src/__tests__/integration/basic/deploy-write-read.test.ts @@ -46,7 +46,7 @@ describe('Testing the SmartWeave client', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/basic/file-cache.test.ts b/src/__tests__/integration/basic/file-cache.test.ts index 0ff8370..f12bbcf 100644 --- a/src/__tests__/integration/basic/file-cache.test.ts +++ b/src/__tests__/integration/basic/file-cache.test.ts @@ -44,7 +44,7 @@ describe('Testing the SmartWeave client', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.fileCached(arweave, cacheDir); + smartweave = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build(); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); @@ -108,11 +108,11 @@ describe('Testing the SmartWeave client', () => { }); it('should properly read state with a fresh client', async () => { - const contract2 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir) + const contract2 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build() .contract(contract.txId()) .connect(wallet); - const contract2VM = SmartWeaveNodeFactory.fileCached(arweave, cacheDir) + const contract2VM = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build() .contract(contract.txId()) .connect(wallet); expect((await contract2.readState()).state.counter).toEqual(559); @@ -127,10 +127,10 @@ describe('Testing the SmartWeave client', () => { }); it('should properly read state with another fresh client', async () => { - const contract3 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir) + const contract3 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build() .contract(contract.txId()) .connect(wallet); - const contract3VM = SmartWeaveNodeFactory.fileCached(arweave, cacheDir) + const contract3VM = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build() .contract(contract.txId()) .setEvaluationOptions({ useVM2: true @@ -153,10 +153,10 @@ describe('Testing the SmartWeave client', () => { await contract.writeInteraction({ function: 'add' }); await mineBlock(arweave); - const contract4 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir) + const contract4 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build() .contract(contract.txId()) .connect(wallet); - const contract4VM = SmartWeaveNodeFactory.fileCached(arweave, cacheDir) + const contract4VM = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build() .contract(contract.txId()) .setEvaluationOptions({ useVM2: true diff --git a/src/__tests__/integration/basic/inf-loop.test.ts b/src/__tests__/integration/basic/inf-loop.test.ts index ef81359..bfd4e85 100644 --- a/src/__tests__/integration/basic/inf-loop.test.ts +++ b/src/__tests__/integration/basic/inf-loop.test.ts @@ -35,7 +35,7 @@ describe('Testing the SmartWeave client', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/basic/knex-cache.test.ts b/src/__tests__/integration/basic/knex-cache.test.ts index a0c4c03..a23fd3a 100644 --- a/src/__tests__/integration/basic/knex-cache.test.ts +++ b/src/__tests__/integration/basic/knex-cache.test.ts @@ -12,6 +12,10 @@ interface ExampleContractState { counter: number; } +async function getSmartWeave(arweave: Arweave, knexConfig: Knex) { + return (await SmartWeaveNodeFactory.knexCachedBased(arweave, knexConfig)).useArweaveGateway().build(); +} + /** * This integration test should verify whether the basic functions of the SmartWeave client * work properly when Knex cache is being used. @@ -64,7 +68,7 @@ describe('Testing the SmartWeave client', () => { LoggerFactory.INST.logLevel('error'); - smartweave = await SmartWeaveNodeFactory.knexCached(arweave, knexConfig); + smartweave = await getSmartWeave(arweave, knexConfig); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); @@ -158,20 +162,20 @@ describe('Testing the SmartWeave client', () => { }); it('should properly read state with a fresh client', async () => { - const contract_1_2 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_1_2 = (await getSmartWeave(arweave, knexConfig)) .contract(contract_1.txId()) .connect(wallet); - const contract_1_2VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_1_2VM = (await getSmartWeave(arweave, knexConfig)) .contract(contract_1.txId()) .setEvaluationOptions({ useVM2: true }) .connect(wallet); expect((await contract_1_2.readState()).state.counter).toEqual(559); expect((await contract_1_2VM.readState()).state.counter).toEqual(559); - const contract_2_2 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_2_2 = (await getSmartWeave(arweave, knexConfig)) .contract(contract_2.txId()) .connect(wallet); - const contract_2_2VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_2_2VM = (await getSmartWeave(arweave, knexConfig)) .contract(contract_2.txId()) .setEvaluationOptions({ useVM2: true }) .connect(wallet); @@ -192,17 +196,17 @@ describe('Testing the SmartWeave client', () => { }); it('should properly read state with another fresh client', async () => { - const contract_1_3 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_1_3 = (await getSmartWeave(arweave, knexConfig)) .contract(contract_1.txId()) .connect(wallet); - const contract_1_3VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_1_3VM = (await getSmartWeave(arweave, knexConfig)) .contract(contract_1.txId()) .setEvaluationOptions({ useVM2: true }) .connect(wallet); - const contract_2_3 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_2_3 = (await getSmartWeave(arweave, knexConfig)) .contract(contract_2.txId()) .connect(wallet); - const contract_2_3VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_2_3VM = (await getSmartWeave(arweave, knexConfig)) .contract(contract_2.txId()) .setEvaluationOptions({ useVM2: true }) .connect(wallet); @@ -233,17 +237,17 @@ describe('Testing the SmartWeave client', () => { await contract_2.writeInteraction({ function: 'add' }); await mineBlock(arweave); - const contract_1_4 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_1_4 = (await getSmartWeave(arweave, knexConfig)) .contract(contract_1.txId()) .connect(wallet); - const contract_1_4VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_1_4VM = (await getSmartWeave(arweave, knexConfig)) .contract(contract_1.txId()) .setEvaluationOptions({ useVM2: true }) .connect(wallet); - const contract_2_4 = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_2_4 = (await getSmartWeave(arweave, knexConfig)) .contract(contract_2.txId()) .connect(wallet); - const contract_2_4VM = (await SmartWeaveNodeFactory.knexCached(arweave, knexConfig)) + const contract_2_4VM = (await getSmartWeave(arweave, knexConfig)) .contract(contract_2.txId()) .setEvaluationOptions({ useVM2: true }) .connect(wallet); @@ -259,7 +263,7 @@ describe('Testing the SmartWeave client', () => { }); it('should allow to manually flush cache', async () => { - const smartweave = await SmartWeaveNodeFactory.knexCached(arweave, knexConfig2); + const smartweave = await getSmartWeave(arweave, knexConfig2); const contract = smartweave .contract(contract_1.txId()) diff --git a/src/__tests__/integration/basic/pst-filecached.test.ts b/src/__tests__/integration/basic/pst-filecached.test.ts index e4fce16..289e7f7 100644 --- a/src/__tests__/integration/basic/pst-filecached.test.ts +++ b/src/__tests__/integration/basic/pst-filecached.test.ts @@ -39,7 +39,7 @@ describe('Testing the Profit Sharing Token', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.fileCached(arweave, cacheDir); + smartweave = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build(); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); @@ -123,7 +123,7 @@ describe('Testing the Profit Sharing Token', () => { }); it('should load updated source code', async () => { - const smartweave2 = SmartWeaveNodeFactory.fileCached(arweave, cacheDir); + const smartweave2 = SmartWeaveNodeFactory.fileCachedBased(arweave, cacheDir).useArweaveGateway().build(); // connecting to the PST contract pst = smartweave2.pst(contractTxId); diff --git a/src/__tests__/integration/basic/pst.test.ts b/src/__tests__/integration/basic/pst.test.ts index ad42e62..4e221da 100644 --- a/src/__tests__/integration/basic/pst.test.ts +++ b/src/__tests__/integration/basic/pst.test.ts @@ -42,7 +42,7 @@ describe('Testing the Profit Sharing Token', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/basic/unsafe-contract.test.ts b/src/__tests__/integration/basic/unsafe-contract.test.ts index 3de4bb6..5b500a2 100644 --- a/src/__tests__/integration/basic/unsafe-contract.test.ts +++ b/src/__tests__/integration/basic/unsafe-contract.test.ts @@ -32,7 +32,7 @@ describe('Testing the SmartWeave client', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/internal-writes/internal-write-back.test.ts b/src/__tests__/integration/internal-writes/internal-write-back.test.ts index 046c437..065bb8b 100644 --- a/src/__tests__/integration/internal-writes/internal-write-back.test.ts +++ b/src/__tests__/integration/internal-writes/internal-write-back.test.ts @@ -73,7 +73,7 @@ describe('Testing internal writes', () => { }); async function deployContracts() { - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); @@ -177,11 +177,11 @@ describe('Testing internal writes', () => { }); it('should properly evaluate state with a new client', async () => { - const contractA2 = SmartWeaveNodeFactory.memCached(arweave) + const contractA2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractATxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); - const contractB2 = SmartWeaveNodeFactory.memCached(arweave) + const contractB2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractBTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); @@ -217,11 +217,11 @@ describe('Testing internal writes', () => { }); it('should properly evaluate state with a new client', async () => { - const contractA2 = SmartWeaveNodeFactory.memCached(arweave) + const contractA2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractATxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); - const contractB2 = SmartWeaveNodeFactory.memCached(arweave) + const contractB2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractBTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); @@ -280,11 +280,11 @@ describe('Testing internal writes', () => { }); xit('should properly evaluate state with a new client', async () => { - const contractA2 = SmartWeaveNodeFactory.memCached(arweave) + const contractA2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractATxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); - const contractB2 = SmartWeaveNodeFactory.memCached(arweave) + const contractB2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractBTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); @@ -339,11 +339,11 @@ describe('Testing internal writes', () => { }); it('should properly evaluate state with a new client', async () => { - const contractA2 = SmartWeaveNodeFactory.memCached(arweave) + const contractA2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractATxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); - const contractB2 = SmartWeaveNodeFactory.memCached(arweave) + const contractB2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractBTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); diff --git a/src/__tests__/integration/internal-writes/internal-write-callee.test.ts b/src/__tests__/integration/internal-writes/internal-write-callee.test.ts index 9f2bd84..c985707 100644 --- a/src/__tests__/integration/internal-writes/internal-write-callee.test.ts +++ b/src/__tests__/integration/internal-writes/internal-write-callee.test.ts @@ -75,7 +75,7 @@ describe('Testing internal writes', () => { }); async function deployContracts() { - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); @@ -262,12 +262,12 @@ describe('Testing internal writes', () => { }); it('should properly evaluate state again with a new client', async () => { - const calleeContract2 = SmartWeaveNodeFactory.memCached(arweave) + const calleeContract2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(calleeTxId) .setEvaluationOptions({ internalWrites: true }); - const calleeContract2VM = SmartWeaveNodeFactory.memCached(arweave) + const calleeContract2VM = SmartWeaveNodeFactory.forTesting(arweave) .contract(calleeTxId) .setEvaluationOptions({ internalWrites: true, diff --git a/src/__tests__/integration/internal-writes/internal-write-caller.test.ts b/src/__tests__/integration/internal-writes/internal-write-caller.test.ts index 367035a..632de9d 100644 --- a/src/__tests__/integration/internal-writes/internal-write-caller.test.ts +++ b/src/__tests__/integration/internal-writes/internal-write-caller.test.ts @@ -87,7 +87,7 @@ describe('Testing internal writes', () => { }); async function deployContracts() { - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/internal-writes/internal-write-depth.test.ts b/src/__tests__/integration/internal-writes/internal-write-depth.test.ts index b5bf27a..31ef666 100644 --- a/src/__tests__/integration/internal-writes/internal-write-depth.test.ts +++ b/src/__tests__/integration/internal-writes/internal-write-depth.test.ts @@ -89,7 +89,7 @@ describe('Testing internal writes', () => { }); async function deployContracts() { - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); @@ -208,11 +208,11 @@ describe('Testing internal writes', () => { }); it('should properly evaluate state with a new client', async () => { - const contractB2 = SmartWeaveNodeFactory.memCached(arweave) + const contractB2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractBTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); - const contractC2 = SmartWeaveNodeFactory.memCached(arweave) + const contractC2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractCTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); diff --git a/src/__tests__/integration/internal-writes/multi-internal-calls.test.ts b/src/__tests__/integration/internal-writes/multi-internal-calls.test.ts index ed6f0d2..7ff5386 100644 --- a/src/__tests__/integration/internal-writes/multi-internal-calls.test.ts +++ b/src/__tests__/integration/internal-writes/multi-internal-calls.test.ts @@ -83,7 +83,7 @@ describe('Testing internal writes', () => { }); async function deployContracts() { - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); @@ -340,11 +340,11 @@ describe('Testing internal writes', () => { }); it('should properly evaluate state with a new client', async () => { - const contractB2 = SmartWeaveNodeFactory.memCached(arweave) + const contractB2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractBTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); - const contractC2 = SmartWeaveNodeFactory.memCached(arweave) + const contractC2 = SmartWeaveNodeFactory.forTesting(arweave) .contract(contractCTxId) .setEvaluationOptions({ internalWrites: true }) .connect(wallet); diff --git a/src/__tests__/integration/internal-writes/staking.test.ts b/src/__tests__/integration/internal-writes/staking.test.ts index 07da4eb..1bbc4d6 100644 --- a/src/__tests__/integration/internal-writes/staking.test.ts +++ b/src/__tests__/integration/internal-writes/staking.test.ts @@ -57,7 +57,7 @@ describe('Testing internal writes', () => { }); async function deployContracts() { - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/wasm/as-deploy-write-read.test.ts b/src/__tests__/integration/wasm/as-deploy-write-read.test.ts index 20e3c59..aacbf9e 100644 --- a/src/__tests__/integration/wasm/as-deploy-write-read.test.ts +++ b/src/__tests__/integration/wasm/as-deploy-write-read.test.ts @@ -39,7 +39,7 @@ describe('Testing the SmartWeave client for AssemblyScript WASM contract', () => LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/wasm/go-deploy-write-read.test.ts b/src/__tests__/integration/wasm/go-deploy-write-read.test.ts index 44f8280..d778a63 100644 --- a/src/__tests__/integration/wasm/go-deploy-write-read.test.ts +++ b/src/__tests__/integration/wasm/go-deploy-write-read.test.ts @@ -45,7 +45,7 @@ describe('Testing the Go WASM Profit Sharing Token', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/integration/wasm/rust-deploy-write-read.test.ts b/src/__tests__/integration/wasm/rust-deploy-write-read.test.ts index 37ef440..66e07dc 100644 --- a/src/__tests__/integration/wasm/rust-deploy-write-read.test.ts +++ b/src/__tests__/integration/wasm/rust-deploy-write-read.test.ts @@ -51,7 +51,7 @@ describe('Testing the Rust WASM Profit Sharing Token', () => { LoggerFactory.INST.logLevel('error'); - smartweave = SmartWeaveNodeFactory.memCached(arweave); + smartweave = SmartWeaveNodeFactory.forTesting(arweave); wallet = await arweave.wallets.generate(); await addFunds(arweave, wallet); diff --git a/src/__tests__/regression/read-state.test.ts b/src/__tests__/regression/read-state.test.ts index 890a0b9..ac20ac0 100644 --- a/src/__tests__/regression/read-state.test.ts +++ b/src/__tests__/regression/read-state.test.ts @@ -111,7 +111,10 @@ describe.each(chunkedGw)('gateways compare.suite %#', (contracts: string[]) => { const resultString = stringify(result.state).trim(); console.log('readState Arweave Gateway', contractTxId); - const result2 = await SmartWeaveNodeFactory.memCached(arweave, 1).contract(contractTxId).readState(blockHeight); + const result2 = await SmartWeaveNodeFactory.memCachedBased(arweave, 1) + .useArweaveGateway() + .build() + .contract(contractTxId).readState(blockHeight); const result2String = stringify(result2.state).trim(); expect(result2String).toEqual(resultString); }, diff --git a/src/core/SmartWeaveBuilder.ts b/src/core/SmartWeaveBuilder.ts index 97c69b4..66b543c 100644 --- a/src/core/SmartWeaveBuilder.ts +++ b/src/core/SmartWeaveBuilder.ts @@ -1,7 +1,8 @@ import Arweave from 'arweave'; import { + ArweaveGatewayInteractionsLoader, CacheableContractInteractionsLoader, - ConfirmationStatus, + ConfirmationStatus, ContractDefinitionLoader, DebuggableExecutorFactory, DefinitionLoader, ExecutorFactory, @@ -84,6 +85,21 @@ export class SmartWeaveBuilder { return this; } + public useArweaveGateway(): SmartWeaveBuilder { + this._definitionLoader = new ContractDefinitionLoader(this._arweave, new MemCache()); + this._interactionsLoader = new CacheableContractInteractionsLoader( + new ArweaveGatewayInteractionsLoader(this._arweave), + new MemBlockHeightSwCache(1) + ); + this._useRedstoneGwInfo = false; + return this; + } + + public useRedStoneGwInfo(): SmartWeaveBuilder { + this._useRedstoneGwInfo = true; + return this; + } + build(): SmartWeave { return new SmartWeave( this._arweave, diff --git a/src/core/node/SmartWeaveNodeFactory.ts b/src/core/node/SmartWeaveNodeFactory.ts index 49a6b6c..660ba82 100644 --- a/src/core/node/SmartWeaveNodeFactory.ts +++ b/src/core/node/SmartWeaveNodeFactory.ts @@ -1,10 +1,13 @@ import Arweave from 'arweave'; import { ArweaveGatewayInteractionsLoader, - CacheableStateEvaluator, + CacheableStateEvaluator, ConfirmationStatus, ContractDefinitionLoader, HandlerExecutorFactory, LexicographicalInteractionsSorter, + R_GW_URL, + RedstoneGatewayContractDefinitionLoader, + RedstoneGatewayInteractionsLoader, SmartWeave, SmartWeaveBuilder, SmartWeaveWebFactory @@ -18,6 +21,13 @@ import { KnexStateCache } from '../../cache/impl/KnexStateCache'; * A {@link SmartWeave} factory that can be safely used only in Node.js env. */ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory { + /** + * Returns a fully configured, memcached {@link SmartWeave} that is suitable for tests with ArLocal + */ + static forTesting(arweave: Arweave): SmartWeave { + return this.memCachedBased(arweave).useArweaveGateway().build(); + } + /** * Returns a fully configured {@link SmartWeave} that is using file-based cache for {@link StateEvaluator} layer * and mem cache for the rest. @@ -41,12 +51,11 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory { static fileCachedBased( arweave: Arweave, cacheBasePath?: string, - maxStoredInMemoryBlockHeights = 10 + maxStoredInMemoryBlockHeights = 10, + confirmationStatus: ConfirmationStatus = { notCorrupted: true } ): SmartWeaveBuilder { - const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache()); - - const gatewayInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave); - + const interactionsLoader = new RedstoneGatewayInteractionsLoader(R_GW_URL, confirmationStatus); + const definitionLoader = new RedstoneGatewayContractDefinitionLoader(R_GW_URL, arweave, new MemCache()); const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache()); const stateEvaluator = new CacheableStateEvaluator( @@ -59,7 +68,8 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory { return SmartWeave.builder(arweave) .setDefinitionLoader(definitionLoader) - .setCacheableInteractionsLoader(gatewayInteractionsLoader) + .setInteractionsLoader(interactionsLoader) + .useRedStoneGwInfo() .setInteractionsSorter(interactionsSorter) .setExecutorFactory(executorFactory) .setStateEvaluator(stateEvaluator); @@ -78,11 +88,11 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory { static async knexCachedBased( arweave: Arweave, dbConnection: Knex, - maxStoredInMemoryBlockHeights = 10 + maxStoredInMemoryBlockHeights = 10, + confirmationStatus: ConfirmationStatus = { notCorrupted: true } ): Promise { - const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache()); - - const gatewayInteractionsLoader = new ArweaveGatewayInteractionsLoader(arweave); + const interactionsLoader = new RedstoneGatewayInteractionsLoader(R_GW_URL, confirmationStatus); + const definitionLoader = new RedstoneGatewayContractDefinitionLoader(R_GW_URL, arweave, new MemCache()); const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache()); @@ -96,7 +106,8 @@ export class SmartWeaveNodeFactory extends SmartWeaveWebFactory { return SmartWeave.builder(arweave) .setDefinitionLoader(definitionLoader) - .setCacheableInteractionsLoader(gatewayInteractionsLoader) + .setInteractionsLoader(interactionsLoader) + .useRedStoneGwInfo() .setInteractionsSorter(interactionsSorter) .setExecutorFactory(executorFactory) .setStateEvaluator(stateEvaluator); diff --git a/src/core/web/SmartWeaveWebFactory.ts b/src/core/web/SmartWeaveWebFactory.ts index c4d874c..879d9f7 100644 --- a/src/core/web/SmartWeaveWebFactory.ts +++ b/src/core/web/SmartWeaveWebFactory.ts @@ -3,9 +3,13 @@ import { CacheableContractInteractionsLoader, CacheableExecutorFactory, Evolve } import { ArweaveGatewayInteractionsLoader, CacheableStateEvaluator, + ConfirmationStatus, ContractDefinitionLoader, HandlerExecutorFactory, LexicographicalInteractionsSorter, + R_GW_URL, + RedstoneGatewayContractDefinitionLoader, + RedstoneGatewayInteractionsLoader, SmartWeave, SmartWeaveBuilder, StateCache @@ -18,44 +22,6 @@ import { MemBlockHeightSwCache, MemCache, RemoteBlockHeightCache } from '@smartw * SmartWeave instances created by this factory can be safely used in a web environment. */ export class SmartWeaveWebFactory { - /** - * Returns a fully configured {@link SmartWeave} that is using remote cache for all layers. - * See {@link RemoteBlockHeightCache} for details. - */ - static remoteCached(arweave: Arweave, cacheBaseURL: string): SmartWeave { - return this.remoteCacheBased(arweave, cacheBaseURL).build(); - } - - /** - * Returns a preconfigured, remoteCached {@link SmartWeaveBuilder}, that allows for customization of the SmartWeave instance. - * Use {@link SmartWeaveBuilder.build()} to finish the configuration. - */ - static remoteCacheBased(arweave: Arweave, cacheBaseURL: string): SmartWeaveBuilder { - const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache()); - - const interactionsLoader = new CacheableContractInteractionsLoader( - new ArweaveGatewayInteractionsLoader(arweave), - new RemoteBlockHeightCache('INTERACTIONS', cacheBaseURL) - ); - - const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache()); - - const stateEvaluator = new CacheableStateEvaluator( - arweave, - new RemoteBlockHeightCache>('STATE', cacheBaseURL), - [new Evolve(definitionLoader, executorFactory)] - ); - - const interactionsSorter = new LexicographicalInteractionsSorter(arweave); - - return SmartWeave.builder(arweave) - .setDefinitionLoader(definitionLoader) - .setInteractionsLoader(interactionsLoader) - .setInteractionsSorter(interactionsSorter) - .setExecutorFactory(executorFactory) - .setStateEvaluator(stateEvaluator); - } - /** * Returns a fully configured {@link SmartWeave} that is using mem cache for all layers. */ @@ -70,17 +36,16 @@ export class SmartWeaveWebFactory { static memCachedBased( arweave: Arweave, maxStoredBlockHeights = 10, - stateCache?: MemBlockHeightSwCache> + confirmationStatus: ConfirmationStatus = { notCorrupted: true } ): SmartWeaveBuilder { - const definitionLoader = new ContractDefinitionLoader(arweave, new MemCache()); - - const interactionsLoader = new ArweaveGatewayInteractionsLoader(arweave); + const interactionsLoader = new RedstoneGatewayInteractionsLoader(R_GW_URL, confirmationStatus); + const definitionLoader = new RedstoneGatewayContractDefinitionLoader(R_GW_URL, arweave, new MemCache()); const executorFactory = new CacheableExecutorFactory(arweave, new HandlerExecutorFactory(arweave), new MemCache()); const stateEvaluator = new CacheableStateEvaluator( arweave, - stateCache ? stateCache : new MemBlockHeightSwCache>(maxStoredBlockHeights), + new MemBlockHeightSwCache>(maxStoredBlockHeights), [new Evolve(definitionLoader, executorFactory)] ); @@ -88,7 +53,8 @@ export class SmartWeaveWebFactory { return SmartWeave.builder(arweave) .setDefinitionLoader(definitionLoader) - .setCacheableInteractionsLoader(interactionsLoader) + .setInteractionsLoader(interactionsLoader) + .useRedStoneGwInfo() .setInteractionsSorter(interactionsSorter) .setExecutorFactory(executorFactory) .setStateEvaluator(stateEvaluator);