This document provides a guide for testing the blockchain integration in the Vyaapar.AI application. It covers the testing of company registration, investment processing, and verification of blockchain data.
Before testing, ensure you have the following:
- A running local blockchain node (Hardhat or Ganache)
- The VyaaparAI smart contract deployed
- Environment variables set up in
.envfile:BLOCKCHAIN_RPC_URL=http://localhost:8545 CONTRACT_ADDRESS=0x... PRIVATE_KEY=0x... API_URL=http://localhost:5000/api
We've created two scripts to help with testing:
This script tests the basic connection to the blockchain and contract functionality.
# Add the script to package.json scripts
npm run test-blockchainTo test minting a company directly on the blockchain:
npm run test-blockchain -- --mintThis script tests the complete blockchain workflow from the API, including:
- Company registration with blockchain verification
- Making an investment with blockchain verification
- Verifying the data on the blockchain
npm run test-workflow-
Connect Wallet:
- Open the application and log in
- Click "Connect Wallet" in the header
- Ensure MetaMask connects successfully
-
Register a Company:
- Navigate to Dashboard → Register Company
- Fill in company details
- Check "Verify on Blockchain" option
- Submit the form
- Approve the transaction in MetaMask when prompted
-
Verify Registration:
- Navigate to Dashboard → Companies
- Find your company in the list
- Verify the "Blockchain Verified" badge is displayed
-
View Company Details:
- Navigate to Dashboard → Companies
- Click on a blockchain-verified company
-
Make an Investment:
- Click "Invest" button
- Enter investment amount and equity percentage
- Check "Process via Blockchain" option
- Submit the investment
- Approve the transaction in MetaMask when prompted
-
Verify Investment:
- Check the company's investments tab
- Verify the investment shows "Blockchain Verified" status
A debug panel is available to verify blockchain data:
- Navigate to Dashboard → Profile
- Click on "Blockchain Debug Panel"
- Check wallet connection status
- View owned company tokens
- Verify transaction history
-
Wallet Connection Issues:
- Ensure MetaMask is installed and unlocked
- Check you're on the correct network (localhost:8545 for development)
- Try disconnecting and reconnecting
-
Transaction Failures:
- Check browser console for errors
- Verify gas settings in MetaMask
- Ensure the wallet has enough ETH for gas fees
-
Contract Interaction Failures:
- Verify contract address is correct in environment variables
- Check that ABI matches deployed contract
- Ensure the contract is deployed on the connected network
Monitor the backend logs for blockchain-related errors:
# Filter backend logs for blockchain-related messages
npm run dev | grep -i blockchainThe main integration points between the application and blockchain are:
-
Frontend:
src/utils/web3.js- Web3 servicesrc/components/Wallet/WalletButton.js- Wallet connectionsrc/pages/Dashboard/RegisterCompany.js- Company registrationsrc/pages/Dashboard/CompanyDetail.js- Investment processing
-
Backend:
config/blockchain.js- Blockchain serviceroutes/companies.js- Company registration APIroutes/investments.js- Investment APIroutes/blockchain.js- Blockchain-specific APIs
After testing, consider the following improvements:
- Add more comprehensive error handling for blockchain transactions
- Implement transaction status monitoring
- Add blockchain event listeners for real-time updates
- Improve the UI feedback during blockchain interactions