Skip to content

Commit

Permalink
Script for testing sequencer switchover
Browse files Browse the repository at this point in the history
  • Loading branch information
szynwelski committed Nov 23, 2023
1 parent 3f81256 commit c0ccb63
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"warp-contracts-plugin-deploy": "1.0.8",
"warp-contracts-plugin-vm2": "1.0.1",
"warp-contracts-plugin-vrf": "^1.0.3",
"ws": "^8.11.0"
"ws": "^8.11.0",
"warp-contracts": "file:lib/cjs"
},
"resolutions": {
"bn.js": "5.2.1",
Expand Down
89 changes: 89 additions & 0 deletions tools/send-interactions-to-sequencer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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://localhost:5666';
const sequencerUrl = 'http://34.141.17.15:5666';
// const sequencerUrl = 'https://gw.warp.cc';
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 = 1000;
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));
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7700,6 +7700,9 @@ warp-contracts-plugin-vrf@^1.0.3:
"@idena/vrf-js" "^1.0.1"
elliptic "^6.5.4"

"warp-contracts@file:lib/cjs":
version "0.0.0"

warp-isomorphic@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/warp-isomorphic/-/warp-isomorphic-1.0.0.tgz#dccccfc046bc6ac77919f8be1024ced1385c70ea"
Expand Down

0 comments on commit c0ccb63

Please sign in to comment.