Skip to content

Commit

Permalink
fix: improve test reliability and nameOp creation
Browse files Browse the repository at this point in the history
- Add service dependencies and readiness checks in docker-compose
- Enhance regtest container with continuous block mining and error handling
- Remove duplicate nameOp creation from tests and add proper waiting
- Add comprehensive logging for better debugging

Co-Authored-By: Nico Krause <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and silkroadnomad committed Dec 23, 2024
1 parent c989239 commit a9a0afe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
5 changes: 4 additions & 1 deletion docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ services:
volumes:
- ./docker/entrypoint.sh:/usr/src/app/entrypoint.sh
# - ./:/usr/src/app/
entrypoint: ["/bin/sh", "-c", "sleep 10 && /usr/src/app/entrypoint.sh generate-key"]
entrypoint: ["/bin/sh", "-c", "while ! nc -z electrumx 8443 || ! nc -z regtest 18443; do echo 'Waiting for services...'; sleep 5; done && sleep 15 && /usr/src/app/entrypoint.sh generate-key"]
depends_on:
- electrumx
- regtest
ports:
- "1235:1235"
- "9091:9091"
Expand Down
33 changes: 28 additions & 5 deletions docker/regtest-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,36 @@ CITIES=("Xi'an" "Dunhuang" "Kashgar" "Samarkand" "Bukhara" "Merv" "Baghdad" "Dam

for city in "${CITIES[@]}"; do
echo "Creating nameOp for $city..."
doichain-cli -regtest -rpcuser=admin -rpcpassword=adminpw -rpcwait name_doi "$city" "value_for_$city"
TXID=$(doichain-cli -regtest -rpcuser=admin -rpcpassword=adminpw -rpcwait name_doi "$city" "value_for_$city")
if [ $? -ne 0 ]; then
echo "Failed to create nameOp for $city"
exit 1
fi
echo "Created nameOp with txid: $TXID"

# Mine a block to confirm the transaction
doichain-cli -regtest -rpcuser=admin -rpcpassword=adminpw -rpcwait generatetoaddress 1 "$NEWADDR"
BLOCK=$(doichain-cli -regtest -rpcuser=admin -rpcpassword=adminpw -rpcwait generatetoaddress 1 "$NEWADDR")
if [ $? -ne 0 ]; then
echo "Failed to mine block for $city nameOp"
exit 1
fi
echo "Mined block $BLOCK to confirm nameOp for $city"

# Verify the name exists
NAME_INFO=$(doichain-cli -regtest -rpcuser=admin -rpcpassword=adminpw -rpcwait name_show "$city")
if [ $? -ne 0 ]; then
echo "Failed to verify nameOp for $city"
exit 1
fi
echo "Verified nameOp exists for $city: $NAME_INFO"
done

echo "Created nameOps for all cities and mined confirmation blocks"

# Keep process alive so container doesn't exit
echo "Tailing debug.log to keep container running..."
tail -f /home/doichain/.doichain/regtest/debug.log
# Mine additional blocks periodically to ensure transactions are confirmed
echo "Starting periodic block mining..."
while true; do
echo "Mining additional block..."
doichain-cli -regtest -rpcuser=admin -rpcpassword=adminpw -rpcwait generatetoaddress 1 "$NEWADDR"
sleep 30
done
39 changes: 12 additions & 27 deletions relay/tests/relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ describe('Doichain Relay Pinning Service Test', function() {
try {
console.log('[Setup] Starting test node setup...');

// Wait for relay service to be ready
console.log('[Setup] Waiting for relay service to be ready...');
await new Promise((resolve) => setTimeout(resolve, 30000));

// Initialize Helia first
console.log('[Setup] Initializing Helia node...');
helia = await createHelia({
Expand Down Expand Up @@ -170,34 +174,15 @@ describe('Doichain Relay Pinning Service Test', function() {
db = await getOrCreateDB(global.orbitdb);
console.log('[Setup] NameOps database initialized');

// Create nameOps with Silk Road city names
console.log('[Setup] Creating nameOps with Silk Road city names...');
const silkRoadCities = [
'Xian', 'Luoyang', 'Dunhuang', 'Kashgar', 'Samarkand',
'Bukhara', 'Merv', 'Baghdad', 'Damascus', 'Constantinople',
'Antioch', 'Tyre', 'Alexandria', 'Balkh', 'Taxila',
'Peshawar', 'Kucha', 'Turpan', 'Hotan', 'Lanzhou'
];

for (const city of silkRoadCities) {
const nameOp = {
txid: `${Date.now()}-${city.toLowerCase()}`,
nameId: `test/${city.toLowerCase()}`,
nameValue: `City of ${city} on the Silk Road`,
blockHeight: 200,
blocktime: Math.floor(Date.now() / 1000),
blockDate: new Date().toISOString()
};
await db.put({
_id: nameOp.txid,
nameOp,
blockHeight: nameOp.blockHeight,
blockDate: nameOp.blockDate,
timestamp: new Date().toISOString()
});
console.log(`[Setup] Created nameOp for ${city}`);
// Wait for nameOps to be created by regtest container and indexed
console.log('[Setup] Waiting for nameOps to be indexed...');
try {
await waitForNameOps(global.orbitdb);
console.log('[Setup] Successfully verified nameOps are indexed');
} catch (error) {
console.error('[Setup] Failed waiting for nameOps:', error);
throw error;
}
console.log('[Setup] Finished creating nameOps');

helia = await createHelia({
libp2p: {
Expand Down

0 comments on commit a9a0afe

Please sign in to comment.