-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script for testing sequencer switchover
- Loading branch information
1 parent
889a3f5
commit 9402581
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import ArLocal from "arlocal"; | ||
import Arweave from "arweave"; | ||
import { EvalStateResult, SortKeyCacheResult, SourceType, WarpFactory, defaultCacheOptions, defaultWarpGwOptions, sleep } from "../src"; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { ArweaveSigner } from "warp-arbundles"; | ||
import { DeployPlugin } from "warp-contracts-plugin-deploy"; | ||
|
||
interface ExampleContractState { | ||
counter: number; | ||
} | ||
|
||
async function main() { | ||
const sequencerUrl = 'http://34.141.17.15:5666'; | ||
// const sequencerUrl = 'http://localhost:5666'; | ||
const arweavePort = 1983; | ||
const arlocal = new ArLocal(arweavePort, false); | ||
|
||
try { | ||
await arlocal.start(); | ||
const arweave = Arweave.init({ | ||
host: 'localhost', | ||
port: arweavePort, | ||
protocol: 'http' | ||
}); | ||
|
||
const cacheOptions = { | ||
...defaultCacheOptions, | ||
inMemory: true | ||
} | ||
const gatewayOptions = { ...defaultWarpGwOptions, source: SourceType.WARP_SEQUENCER, confirmationStatus: { notCorrupted: true } } | ||
|
||
const warp = WarpFactory | ||
.custom(arweave, cacheOptions, 'custom') | ||
.useWarpGateway(gatewayOptions, cacheOptions) | ||
.build() | ||
.use(new DeployPlugin()) | ||
.useGwUrl(sequencerUrl) | ||
|
||
const contractSrc = fs.readFileSync(path.join(__dirname, '../src/__tests__/integration/data/example-contract.js'), 'utf8'); | ||
const initialState = fs.readFileSync(path.join(__dirname, '../src/__tests__/integration/data/example-contract-state.json'), 'utf8'); | ||
const wallet = (await warp.generateWallet()).jwk; | ||
const { contractTxId } = await warp.deploy({ | ||
wallet: new ArweaveSigner(wallet), | ||
initState: initialState, | ||
src: contractSrc | ||
}); | ||
const contract = warp.contract<ExampleContractState>(contractTxId).setEvaluationOptions({ | ||
sequencerUrl: sequencerUrl, | ||
waitForConfirmation: true | ||
}); | ||
contract.connect(wallet); | ||
|
||
const initCounter = 555; | ||
const numberOfInteractions = 100; | ||
let counter = initCounter; | ||
let state: SortKeyCacheResult<EvalStateResult<ExampleContractState>> | undefined; | ||
let contractCounter: number; | ||
while (counter < initCounter + numberOfInteractions) { | ||
try { | ||
const response = await contract.writeInteraction({ function: 'add' }) | ||
console.log('interaction response', response); | ||
counter++; | ||
} catch(e) { | ||
console.error("interaction failed", e); | ||
} | ||
|
||
try { | ||
state = await contract.readState(); | ||
} catch(e) { | ||
console.error("read state failed", e); | ||
state = undefined; | ||
} | ||
if (state) { | ||
contractCounter = state.cachedValue.state.counter | ||
console.log('counter from contract', counter) | ||
if (contractCounter !== counter) { | ||
throw new Error("Invalid counter value. Expected: " + counter + " actual: " + contractCounter); | ||
} | ||
} | ||
await sleep(1000); | ||
} | ||
} finally { | ||
await arlocal.stop(); | ||
} | ||
} | ||
|
||
main().catch((e) => console.error(e)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters