Skip to content

Commit

Permalink
Merge pull request #29 from mc-putchar/dev
Browse files Browse the repository at this point in the history
.
  • Loading branch information
CarloCattano authored Oct 1, 2024
2 parents dcc3d1f + f9fb380 commit 819067c
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 361 deletions.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ COLOUR_MAGB := \033[1;35m
COLOUR_CYN := \033[36m
COLOUR_CYNB := \033[1;36m

.PHONY: help up down start stop re logs logs-django ps db-shell migrate debug clean shred collect schema newkey swapmode maintenance cli CLI testlogin tests
.PHONY: help up down start stop re logs logs-django ps db-shell migrate debug clean shred collect schema newkey swapmode maintenance cli CLI testlogin tests testblockchain

help: # Display this helpful message
@awk 'BEGIN { \
Expand Down Expand Up @@ -131,11 +131,14 @@ testlogin: # Selenium tests
docker exec ft_transcendence-django-1 python test_selenium.py
@echo "Test done"

tests: # Run automated tests
# $(DC) -f $(SRC) start
# @docker exec -it ft_transcendence-blockchain-1 sh -c "npx hardhat test"
testcontract: # Run smart contract tests (run while containers are not running)
@echo -e "$(COLOUR_MAGB)Testing smart contract$(COLOUR_END)"
$(DC) -f $(SRC) run --rm blockchain npx hardhat test
# $(DC) -f $(SRC) run --rm django python manage.py test # should run on separate test volume
$(DC) -f $(SRC) stop

testblockchain: # Run blockchain tests (run while containers are running)
@echo -e "$(COLOUR_MAGB)Testing committing data to the blockchain$(COLOUR_END)"
@echo -e "$(COLOUR_GREEN)Adding matches$(COLOUR_END)"
docker exec -it ft_transcendence-django-1 python manage.py test blockchain.tests.AddMatchViewTest
@echo -e "$(COLOUR_GREEN)Adding tournaments$(COLOUR_END)"
docker exec -it ft_transcendence-django-1 python manage.py test blockchain.tests.CommitTournamentViewTest
11 changes: 11 additions & 0 deletions is_deployed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from blockchain.blockchain_api import PongBlockchain

def main(*args, **kwargs):
if len(args) == 0:
return (1)
chain = PongBlockchain()
print(f"Blockchain connected: {chain.is_connected()}")
print(f"Connecting to {args[0]}... ")
chain.connect(args[0])
print(f"Connected to {args[0]}: {chain.is_connected()}")

27 changes: 27 additions & 0 deletions pong/blockchain/blockchain_explorer/add_player.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

if [ "$#" -ne 4 ]; then
echo "Usage: $0 <contract_eth_address> <username> <email> <database_uid> <account_eth_address>"
exit 1
fi

docker exec -it ft_transcendence-django-1 python -c "
from blockchain.blockchain_api import PongBlockchain, hash_player
import dotenv
dotenv.load_dotenv()
chain = PongBlockchain()
chain.connect($1)
print(f'Contract deployed: {chain.is_deployed}')
if not chain.is_deployed:
print('Contract not deployed')
exit(1)
pk = os.getenv('HARDHAT_PRIVATE_KEY').strip('"')
sender = chain.accounts[0]
player_hash = hash_player([$3, $4])
status = chain.addPlayerSimple(sender, pk, player_hash, $2)
if status['status'] == 1:
print(f'Player $2 added: with hash {player_hash}')
else:
print(f'Player $2 not added')
"
26 changes: 26 additions & 0 deletions pong/blockchain/blockchain_explorer/bc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
RELATIVE_PATH=.

helpFunction()
{
echo "Usage: $0 <command> <args>"
echo -e "\tis_connected"
echo -e "\tis_deployed <eth_address>"
exit 1 # Exit script after printing help
}

if [ "$#" -lt 1 ]; then
helpFunction
exit 1
fi

case $1 in
"is_connected")
echo "Checking connection status..."
$RELATIVE_PATH/is_connected.sh
;;
"is_deployed")
echo "Checking deployment status..."
$RELATIVE_PATH/is_deployed.sh $2
;;
esac
5 changes: 5 additions & 0 deletions pong/blockchain/blockchain_explorer/is_connected.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

docker exec -it ft_transcendence-django-1 python -c "from blockchain.blockchain_api import PongBlockchain;\
chain = PongBlockchain();\
print(f'Blockchain connected: {chain.is_connected()}');"
12 changes: 12 additions & 0 deletions pong/blockchain/blockchain_explorer/is_deployed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <eth_address>"
exit 1
fi

docker exec -it ft_transcendence-django-1 python -c "from blockchain.blockchain_api import PongBlockchain;\
chain = PongBlockchain();\
print(f'Blockchain connected: {chain.is_connected()}');\
chain.connect($1);\
print(f'Connected to {hex($1)}: {chain.is_connected()}');"
56 changes: 0 additions & 56 deletions pong/blockchain/experimental/compile_experimental.py

This file was deleted.

169 changes: 0 additions & 169 deletions pong/blockchain/experimental/deploy_experimental.py

This file was deleted.

Loading

0 comments on commit 819067c

Please sign in to comment.