Skip to content

Commit

Permalink
Add more test files
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Dec 19, 2023
1 parent f92127d commit 9187f39
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 24 deletions.
10 changes: 10 additions & 0 deletions test-mutation/all-configs/config.single.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
}
]
106 changes: 106 additions & 0 deletions test-mutation/all-configs/config.tokenbridge-ethereum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[
{
"filename": "../contracts/tokenbridge/ethereum/L1ArbitrumMessenger.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ArbitrumExtendedGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ArbitrumGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ForceOnlyReverseCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitERC20Gateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitGatewayRouter.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitReverseCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
}
]
84 changes: 82 additions & 2 deletions test-mutation/config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
[
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol",
"filename": "../contracts/tokenbridge/ethereum/L1ArbitrumMessenger.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1CustomGateway.sol",
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ArbitrumExtendedGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ArbitrumGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
Expand All @@ -22,5 +30,77 @@
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ERC20Gateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ForceOnlyReverseCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitERC20Gateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitGatewayRouter.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1OrbitReverseCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1ReverseCustomGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
},
{
"filename": "../contracts/tokenbridge/ethereum/gateway/L1WethGateway.sol",
"sourceroot": "..",
"solc_remappings": [
"@openzeppelin=../node_modules/@openzeppelin",
"@arbitrum=../node_modules/@arbitrum"
]
}
]
31 changes: 9 additions & 22 deletions test-mutation/gambitTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const TEST_TIMES = [
'test-foundry',
]
const MAX_TASKS = os.cpus().length - 1
const TASK_TIMEOUT = 3 * 60 * 1000 // 3min

const execAsync = promisify(exec)
const symlink = promisify(fs.symlink)
Expand All @@ -35,7 +34,6 @@ interface TestResult {
enum MutantStatus {
KILLED = 'KILLED',
SURVIVED = 'SURVIVED',
TIMEOUT = 'TIMEOUT',
}

runMutationTesting().catch(error => {
Expand All @@ -60,7 +58,9 @@ async function runMutationTesting() {

// Print time testing took
const endTime = Date.now()
console.log(`\n====== Done in ${(endTime - startTime) / (60 * 1000)} min`)
console.log(
`\n====== Done in ${((endTime - startTime) / (60 * 1000)).toFixed(2)} min`
)
}

async function _generateMutants(): Promise<Mutant[]> {
Expand Down Expand Up @@ -121,23 +121,13 @@ async function _testMutant(mutant: Mutant): Promise<TestResult> {
// Re-build and test
let mutantStatus: MutantStatus
try {
await Promise.race([
(async () => {
await execAsync(`forge build --root ${testDirectory}`)
await execAsync(`forge test --root ${testDirectory}`)
mutantStatus = MutantStatus.SURVIVED
})(),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), TASK_TIMEOUT)
),
])
await execAsync(`forge build --root ${testDirectory}`)
await execAsync(
`forge test --fail-fast --gas-limit 30000000 --root ${testDirectory}`
)
mutantStatus = MutantStatus.SURVIVED
} catch (error) {
if (error instanceof Error) {
mutantStatus =
error.message === 'Timeout' ? MutantStatus.TIMEOUT : MutantStatus.KILLED
} else {
mutantStatus = MutantStatus.KILLED
}
mutantStatus = MutantStatus.KILLED
}

// delete test folder
Expand All @@ -158,7 +148,6 @@ function _printResults(results: TestResult[]) {
let lastFileName = ''
let killedCount = 0
let survivedCount = 0
let timeoutCount = 0

/// print table and count stats
results.forEach(result => {
Expand All @@ -176,8 +165,6 @@ function _printResults(results: TestResult[]) {
killedCount++
} else if (result.status === MutantStatus.SURVIVED) {
survivedCount++
} else {
timeoutCount++
}
})

Expand Down

0 comments on commit 9187f39

Please sign in to comment.