Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ce4df91
Update socket-protocol submodule to latest dev
rookmate Jun 2, 2025
c5dda8a
chore: change DeliveryHelper.t.sol to SetupTest.t.sol
rookmate Jun 2, 2025
dc7d779
chore: update initialize to initializeOnChain
rookmate Jun 2, 2025
81deadf
chore: update withdrawFeeTokens to withdrawCredits
rookmate Jun 2, 2025
5cc2919
chore: update timeouts to schedules
rookmate Jun 2, 2025
d8dc450
chore: change watcher precompile to watcher
rookmate Jun 2, 2025
a6c754b
chore: update constructor initialization params
rookmate Jun 2, 2025
abd2db7
chore: revert modifier async(bytes()) to async
rookmate Jun 2, 2025
9a0d548
chore: getOrDeployForwarderContract with asyncDeployer
rookmate Jun 2, 2025
668b88a
fix: add missing _initializeAppGateway to constructor
rookmate Jun 2, 2025
5de2358
chore: add license to package.json
rookmate Jun 2, 2025
1d2ab03
fix: numberOfEvents to wait is now dynamic
rookmate Jun 3, 2025
b5bee6d
chore: update deposit function name
rookmate Jun 3, 2025
7cd2695
fix: contracts calling wrong then function
rookmate Jun 3, 2025
9e862ad
fix: add missing public to read contract
rookmate Jun 3, 2025
59e1eff
fix: numberOfRequests consistent with read contract
rookmate Jun 3, 2025
672f6f4
fix: add missing async modifier
rookmate Jun 3, 2025
2e4cf7b
fix: revert test validation
rookmate Jun 3, 2025
9456705
fix: remove async when not needed
rookmate Jun 3, 2025
984bdc7
fix: change max fees to half of deploy fees
rookmate Jun 3, 2025
e50c3d2
chore: add transferCredits and setMaxFees to all contracts
rookmate Jun 3, 2025
c2ae82e
fix: withdraw fees logic
rookmate Jun 3, 2025
2893da7
chore: add TODO on depositFunds
rookmate Jun 3, 2025
a94a464
chore: remove TODO as issue is solved
rookmate Jun 3, 2025
a93fe13
Update socket-protocol submodule to latest staging
rookmate Jun 3, 2025
4e05626
Update socket-protocol submodule to latest dev
rookmate Jun 3, 2025
1a1bcdd
chore: change transfer amount to 10 USDC
rookmate Jun 3, 2025
35eeac6
chore: update withdrawCredits
rookmate Jun 3, 2025
ba7843d
feat: sendTransaction now supports value
rookmate Jun 3, 2025
f158351
fix: add 1sec delay after confirming funds
rookmate Jun 3, 2025
6c0ac9b
cheeky commit. needs to be reverted
rookmate Jun 4, 2025
3c2d046
feat: add support for mainnet chains
rookmate Jun 4, 2025
f34c31f
fix: delay 1sec after fetching addresses
rookmate Jun 4, 2025
b0f341d
chore: update .env.sample
rookmate Jun 4, 2025
6af1575
chore: update fee plug address
rookmate Jun 4, 2025
5def436
chore: update fee plug address
rookmate Jun 4, 2025
71ac547
Update socket-protocol submodule to latest master
rookmate Jun 4, 2025
df0fe79
chore: update constants
rookmate Jun 4, 2025
a2ec883
fix: deposit funds function
rookmate Jun 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# RPCs
EVMX_RPC="https://rpc-evmx-devnet.socket.tech/"

SEPOLIA_RPC="https://ethereum-sepolia-rpc.publicnode.com"
ARBITRUM_SEPOLIA_RPC="https://sepolia-rollup.arbitrum.io/rpc"
OPTIMISM_SEPOLIA_RPC="https://sepolia.optimism.io"
BASE_SEPOLIA_RPC="https://sepolia.base.org"

ARBITRUM_RPC="https://arbitrum.drpc.org"
OPTIMISM_RPC="https://optimism.drpc.org"
BASE_RPC="https://base.drpc.org"

# EVMx key addresses
# Find the most up to date addresses at:
# https://github.com/SocketDotTech/socket-protocol/blob/master/deployments/stage_addresses.json
ADDRESS_RESOLVER="0x21a9AFDfbEb0399D4a12f3AA1324042Be2B57F8e"
FEES_MANAGER="0x30e07016eB24570629Bc8765CA307394Af90B27C"
ARBITRUM_FEES_PLUG="0xDfE94B9b14de382Ed13C8A7F387884808D0f7E0b"
ARBITRUM_TEST_USDC="0xa03Cbf13f331aF7c0fD7F2E28E6Cbc13F879E3F3"
ADDRESS_RESOLVER="0x935b06902cA5C8bb4C76e18738561c294D377A93"
FEES_MANAGER="0xA07208F9e7aE243F922317ab6604DC9F86822406"
ARBITRUM_FEES_PLUG="0x501bdF8C7163ddD32172575C2836c5A7F556cbE7"
ARBITRUM_USDC="0xaf88d065e77c8cC2239327C5EDb3A432268e5831"

# Add your deployer private key here
# or remove it from this file if it is already an env var
Expand Down
2 changes: 1 addition & 1 deletion lib/socket-protocol
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"license": "MIT",
"type": "module",
"dependencies": {
"dotenv": "^16.5.0",
Expand Down
41 changes: 10 additions & 31 deletions script/runIntegrationTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setupClients } from './utils/client-setup.js';
import { getAvailableChains } from './utils/client-setup.js';
import { buildContracts } from './utils/deployer.js';
import { ChainConfig, TestFlags } from './utils/types.js';
import { TestFlags } from './utils/types.js';
import { COLORS } from './utils/constants.js';

// Import test modules
Expand All @@ -12,19 +12,6 @@ import { executeSchedulerTests } from './tests/scheduler_tests.js';
import { executeInsufficientFeesTests } from './tests/insufficient_tests.js';
import { executeRevertTests } from './tests/revert_tests.js';

// Global chain configurations
let evmxChain: ChainConfig;
let arbChain: ChainConfig;
let opChain: ChainConfig;

// Initialize chains
function initializeChains(): void {
const chains = setupClients();
evmxChain = chains.evmxChain;
arbChain = chains.arbChain;
opChain = chains.opChain;
}

// Help function
function showHelp(): void {
console.log('Usage: npx tsx tests.ts [OPTIONS]');
Expand Down Expand Up @@ -59,7 +46,7 @@ function parseFlags(args: string[]): TestFlags {
async function main(): Promise<void> {
try {
await buildContracts();
initializeChains();
const chains = getAvailableChains();

// Parse command line arguments
const args = process.argv.slice(2);
Expand All @@ -72,31 +59,31 @@ async function main(): Promise<void> {

// Execute tests based on flags
if (flags.write) {
await executeWriteTests(evmxChain, arbChain);
await executeWriteTests(chains.evmxChain, chains.arbChain);
}

if (flags.read) {
await executeReadTests(evmxChain, arbChain);
await executeReadTests(chains.evmxChain, chains.arbChain);
}

if (flags.trigger) {
await executeTriggerTests(evmxChain, arbChain, opChain);
await executeTriggerTests(chains.evmxChain, chains.arbChain, chains.opChain);
}

if (flags.upload) {
await executeUploadTests(evmxChain, arbChain);
await executeUploadTests(chains.evmxChain, chains.arbChain);
}

if (flags.scheduler) {
await executeSchedulerTests(evmxChain, arbChain);
await executeSchedulerTests(chains.evmxChain, chains.arbChain);
}

if (flags.insufficient) {
await executeInsufficientFeesTests(evmxChain, arbChain);
await executeInsufficientFeesTests(chains.evmxChain, chains.arbChain);
}

if (flags.revert) {
await executeRevertTests(evmxChain, arbChain);
await executeRevertTests(chains.evmxChain, chains.arbChain);
}

console.log(`${COLORS.GREEN}All selected tests completed successfully!${COLORS.NC}`);
Expand All @@ -107,14 +94,6 @@ async function main(): Promise<void> {
}
}

// Export the setup for external use
export {
initializeChains,
evmxChain,
arbChain,
opChain
};

// Run main if this is the main module
if (import.meta.url === `file://${process.argv[1]}`) {
main().catch((error) => {
Expand Down
11 changes: 9 additions & 2 deletions script/tests/read_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export async function runReadTests(
console.log(`${COLORS.CYAN}Running all read tests functions...${COLORS.NC}`);

const abi = parseAbi([
'function numberOfRequests() external view returns (uint256)',
'function triggerParallelRead(address forwarder) external',
'function triggerAltRead(address forwarder1, address forwarder2) external'
]);
Expand All @@ -21,6 +22,12 @@ export async function runReadTests(
throw new Error('Required addresses not found');
}

const numberOfRequests = await evmxChain.client.readContract({
address: addresses.appGateway,
abi,
functionName: 'numberOfRequests',
});

// 1. Trigger Parallel Read
await sendTransaction(
addresses.appGateway,
Expand All @@ -29,7 +36,7 @@ export async function runReadTests(
evmxChain,
abi
);
await awaitEvents(10, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain);
await awaitEvents(numberOfRequests, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain);

// 2. Trigger Alternating Read
await sendTransaction(
Expand All @@ -39,7 +46,7 @@ export async function runReadTests(
evmxChain,
abi
);
await awaitEvents(20, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain);
await awaitEvents(numberOfRequests * 2n, 'ValueRead(address,uint256,uint256)', addresses.appGateway, evmxChain);
}

export async function executeReadTests(
Expand Down
29 changes: 13 additions & 16 deletions script/tests/revert_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,36 @@ export async function runRevertTests(
abi
);

console.log(`${COLORS.CYAN}Waiting for transaction finalization${COLORS.NC}`);
console.log(`${COLORS.CYAN}Waiting for transaction proof${COLORS.NC}`);
let attempt = 0;
let status = '';

let execStatus;
while (true) {
const response = await getTxDetails(endpoint, hash1);
status = response?.response?.[0]?.writePayloads?.[0]?.finalizeDetails?.finalizeStatus;

if (status === 'FINALIZED') {
if (attempt > 0) process.stdout.write('\r\x1b[2K');
break;
status = response?.response?.[0]?.writePayloads?.[0]?.proofUploadDetails?.proofUploadStatus;

if (status === 'PROOF_UPLOADED') {
execStatus = response?.response?.[0]?.writePayloads?.[0]?.executeDetails?.executeStatus;
if (execStatus === 'EXECUTION_FAILED') {
console.log(`Execution status is EXECUTION_FAILED as expected`);
if (attempt > 0) process.stdout.write('\r\x1b[2K');
break;
}
}

if (attempt >= maxAttempts) {
console.log();
throw new Error(`Transaction not finalized after ${maxSeconds} seconds. Current status: ${status}`);
throw new Error(`Could not validate failed execution after ${maxSeconds} seconds. Current status: ${status}`);
}

const elapsed = attempt * interval / 1000;
process.stdout.write(`\r${COLORS.YELLOW}Waiting for finalization:${COLORS.NC} ${elapsed}s / ${maxSeconds}s`);
process.stdout.write(`\r${COLORS.YELLOW}Waiting for failed execution:${COLORS.NC} ${elapsed}s / ${maxSeconds}s`);

await new Promise(resolve => setTimeout(resolve, interval));
attempt++;
}

const execStatus = (await getTxDetails(endpoint, hash1))?.response?.[0]?.writePayloads?.[0]?.executeDetails?.executeStatus;

if (execStatus === 'EXECUTION_FAILED') {
console.log(`Execution status is EXECUTION_FAILED as expected`);
} else {
throw new Error(`Execution status is not EXECUTION_FAILED, it is: ${execStatus}`);
}

// Send callback revert transaction
console.log(`${COLORS.CYAN}Testing callback revert${COLORS.NC}`);

Expand Down
40 changes: 20 additions & 20 deletions script/tests/scheduler_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,53 @@ export async function runSchedulerTests(
appGateway: Address,
evmxChain: ChainConfig
): Promise<void> {
console.log(`${COLORS.CYAN}Reading timeouts from the contract:${COLORS.NC}`);
console.log(`${COLORS.CYAN}Reading schedules from the contract:${COLORS.NC}`);
const abi = parseAbi([
'function timeoutsInSeconds(uint256) external view returns (uint256)',
'function triggerTimeouts() external'
'function schedulesInSeconds(uint256) external view returns (uint256)',
'function triggerSchedules() external'
]);

let maxTimeout = 0;
let numberOfTimeouts = 0;
let maxSchedule = 0n;
let numberOfSchedules = 0n;

while (true) {
try {
const timeout = await evmxChain.client.readContract({
const schedule = await evmxChain.client.readContract({
address: appGateway,
abi,
functionName: 'timeoutsInSeconds',
args: [numberOfTimeouts]
}) as number;
functionName: 'schedulesInSeconds',
args: [numberOfSchedules]
});

if (timeout === 0) break;
if (schedule === 0) break;

console.log(`Timeout ${numberOfTimeouts}: ${timeout} seconds`);
numberOfTimeouts++;
console.log(`Schedule ${numberOfSchedules}: ${schedule} seconds`);
numberOfSchedules++;

if (timeout > maxTimeout) {
maxTimeout = timeout;
if (schedule > maxSchedule) {
maxSchedule = schedule;
}
} catch (error) {
break;
}
}

console.log(`${COLORS.CYAN}Triggering timeouts...${COLORS.NC}`);
console.log(`${COLORS.CYAN}Triggering schedules...${COLORS.NC}`);
await sendTransaction(
appGateway,
'triggerTimeouts',
'triggerSchedules',
[],
evmxChain,
abi
);

console.log(`${COLORS.CYAN}Fetching TimeoutResolved events...${COLORS.NC}`);
console.log(`${COLORS.CYAN}Fetching ScheduleResolved events...${COLORS.NC}`);

await awaitEvents(numberOfTimeouts, 'TimeoutResolved(uint256,uint256,uint256)', appGateway, evmxChain, Number(maxTimeout));
await awaitEvents(numberOfSchedules, 'ScheduleResolved(uint256,uint256,uint256)', appGateway, evmxChain, Number(maxSchedule));

const logs = await evmxChain.client.getLogs({
address: appGateway,
event: parseAbi(['event TimeoutResolved(uint256,uint256,uint256)'])[0],
event: parseAbi(['event ScheduleResolved(uint256,uint256,uint256)'])[0],
fromBlock: 'earliest',
toBlock: 'latest'
});
Expand All @@ -69,7 +69,7 @@ export async function runSchedulerTests(
const creationTimestamp = BigInt('0x' + dataHex.slice(64, 128));
const executionTimestamp = BigInt('0x' + dataHex.slice(128, 192));

console.log(`${COLORS.GREEN}Timeout Resolved:${COLORS.NC}`);
console.log(`${COLORS.GREEN}Schedule Resolved:${COLORS.NC}`);
console.log(` Index: ${index}`);
console.log(` Created at: ${creationTimestamp}`);
console.log(` Executed at: ${executionTimestamp}`);
Expand Down
2 changes: 1 addition & 1 deletion script/tests/upload_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function runUploadTests(
uploadAbi
);

await awaitEvents(1, 'ReadOnchain(address,uint256)', appGateway, evmxChain);
await awaitEvents(1n, 'ReadOnchain(address,uint256)', appGateway, evmxChain);
}

export async function executeUploadTests(
Expand Down
14 changes: 11 additions & 3 deletions script/tests/write_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export async function runWriteTests(
console.log(`${COLORS.CYAN}Running all write tests functions...${COLORS.NC}`);

const abi = parseAbi([
'function numberOfRequests() external view returns (uint256)',
'function triggerSequentialWrite(address forwarder) external',
'function triggerParallelWrite(address forwarder) external',
'function triggerAltWrite(address forwarder1, address forwarder2) external'
Expand All @@ -22,6 +23,13 @@ export async function runWriteTests(
throw new Error('Required addresses not found');
}

const numberOfRequests = await evmxChain.client.readContract({
address: addresses.appGateway,
abi,
functionName: 'numberOfRequests',
});


// 1. Trigger Sequential Write
await sendTransaction(
addresses.appGateway,
Expand All @@ -30,7 +38,7 @@ export async function runWriteTests(
evmxChain,
abi
);
await awaitEvents(10, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain);
await awaitEvents(numberOfRequests, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain);

// 2. Trigger Parallel Write
await sendTransaction(
Expand All @@ -40,7 +48,7 @@ export async function runWriteTests(
evmxChain,
abi
);
await awaitEvents(20, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain);
await awaitEvents(numberOfRequests * 2n, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain);

// 3. Trigger Alternating Write
await sendTransaction(
Expand All @@ -50,7 +58,7 @@ export async function runWriteTests(
evmxChain,
abi
);
await awaitEvents(30, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain);
await awaitEvents(numberOfRequests * 3n, 'CounterIncreased(address,uint256,uint256)', addresses.appGateway, evmxChain);
}

export async function executeWriteTests(
Expand Down
Loading