Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ethereum": {
"rpcUrl": "https://sepolia.infura.io/v3/f3bd3bda446041ff9eea71b40e6072e3",
"privateKey": "03d46f7c5b0ad0cbf4d0bcbcf035b6bd91d95c2f0f09c3e6c387bf24bebccf3e"
}
}
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "verification-layer-tester",
"version": "1.0.0",
"type": "module",
"dependencies": {
"ethers": "^5.8.0"
}
}
21 changes: 21 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// src/cli.js

import testDoubleSpending from "./tests/security/double-spending.js";
import config from "../config/config.js";

// Kullanıcıdan gelen komutu al
const command = process.argv[2]; // process.argv[2] ile terminalde girilen komutu alırız

if (command === "test-double-spending") {
try {
const result = await testDoubleSpending(
config.ethereum.rpcUrl,
config.ethereum.privateKey
);
console.log("Double-spending test sonucu:", result);
} catch (error) {
console.error("Test sırasında bir hata oluştu:", error.message);
}
} else {
console.log("Geçersiz komut. Kullanım: node src/cli.js test-double-spending");
}
54 changes: 54 additions & 0 deletions src/tests/security/double-spending.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// src/tests/security/double-spending.js

import { ethers } from "ethers";

/**
* Double-spending testi yapar.
* @param {string} providerUrl - Ethereum RPC URL'si.
* @param {string} privateKey - Test hesabı private key'i.
*/
async function testDoubleSpending(providerUrl, privateKey) {
// Ethereum sağlayıcısını oluştur
const provider = new ethers.providers.JsonRpcProvider(providerUrl);

// Cüzdan oluştur
const wallet = new ethers.Wallet(privateKey, provider);

console.log(`Cüzdan adresi: ${wallet.address}`);

// Mevcut nonce değerini al
const nonce = await provider.getTransactionCount(wallet.address, "latest");
console.log(`Mevcut nonce değeri: ${nonce}`);

// İlk işlemi gönder
const tx1 = await wallet.sendTransaction({
to: "0x95a35a95E839D6164E390a41deAD4300eda8271b", // Gerçek bir Ethereum adresi girin
value: ethers.utils.parseEther("0.0002"), // Gönderilecek miktar
nonce: nonce, // Aynı nonce değeri
});

console.log(`İlk işlem hash'i: ${tx1.hash}`);

// İlk işlemin bloğa dahil olmasını bekle
console.log("İlk işlemin onaylanması bekleniyor...");
await provider.waitForTransaction(tx1.hash);
console.log("İlk işlem onaylandı.");

// İkinci işlemi gönder (aynı nonce ile)
try {
const tx2 = await wallet.sendTransaction({
to: "0x82C25Ee97B0C4F3bCF316baa888d91A884cC2fe8", // Başka bir Ethereum adresi girin
value: ethers.utils.parseEther("0.0002"), // Gönderilecek miktar
nonce: nonce, // Aynı nonce değeri
});

console.log(`İkinci işlem hash'i: ${tx2.hash}`);
console.log("Test Başarısız: İkinci işlem de gönderildi.");
return "Vulnerable";
} catch (error) {
console.log("Test Başarılı: İkinci işlem reddedildi.");
return "Secure";
}
}

export default testDoubleSpending;