This document outlines two approaches for testing the Web3 Transaction Simulator: as a local website and as a Chrome extension.
This method is useful for rapid development and UI testing.
- Create a new directory called
testin your project root - Create an
index.htmlfile in the test directory that simulates a Web3 environment
<!DOCTYPE html>
<html>
<head>
<title>Web3 Transaction Simulator Test</title>
</head>
<body>
<h1>Web3 Transaction Simulator Test Page</h1>
<button id="sendTransaction">Send Test Transaction</button>
<div id="result" style="margin-top: 20px;"></div>
<script>
// Mock ethereum provider
window.ethereum = {
request: async ({ method, params }) => {
if (method === 'eth_sendTransaction') {
console.log('Transaction params:', params);
return '0x123...'; // Mock transaction hash
}
return null;
}
};
// Test transaction
const testTransaction = {
from: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
to: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
value: '0x1',
data: '0x',
};
document.getElementById('sendTransaction').addEventListener('click', async () => {
try {
const result = await window.ethereum.request({
method: 'eth_sendTransaction',
params: [testTransaction]
});
document.getElementById('result').textContent = `Transaction Hash: ${result}`;
} catch (error) {
document.getElementById('result').textContent = `Error: ${error.message}`;
}
});
</script>
</body>
</html>-
Install a local HTTP server (if you don't have one):
npm install -g http-server
-
Navigate to your project directory and start the server:
http-server ./test
-
Open your browser and navigate to
http://localhost:8080 -
Click the "Send Test Transaction" button to simulate a transaction
This method tests the actual extension functionality in Chrome.
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" using the toggle in the top right
- Click "Load unpacked" and select your extension directory
- The extension should now appear in your Chrome toolbar
-
Basic Extension Loading
- Click the extension icon in Chrome
- Verify the popup opens with the correct UI
- Check that the "Ready" status is displayed
-
Integration Testing
- Visit a Web3-enabled website (e.g., Uniswap, OpenSea)
- Initiate a transaction
- Verify the extension intercepts the transaction
- Check simulation results are displayed
-
Manual Testing
- Click the "Simulate Transaction" button
- Verify error handling when no transaction is available
- Check the display of simulation results
-
Inspect Popup
- Right-click the extension icon
- Click "Inspect popup"
- Use Chrome DevTools to debug popup.js
-
Background Script Debugging
- Go to
chrome://extensions/ - Find your extension
- Click "service worker" under "Inspect views"
- Use console for background.js debugging
- Go to
-
Content Script Debugging
- Open DevTools on any webpage
- Check the "Console" tab
- Filter by "Content Script" to see contentScript.js logs