mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-25 21:33:48 +03:00
Add robot creation tests
This commit is contained in:
parent
b6bbc8c2d0
commit
051c78ab9b
@ -64,7 +64,7 @@ ALTERNATIVE_NAME = 'RoboSats Mainnet'
|
||||
|
||||
# Telegram bot token
|
||||
TELEGRAM_TOKEN = ''
|
||||
TELEGRAM_BOT_NAME = ''
|
||||
TELEGRAM_BOT_NAME = 'RoboCoordinatorNotificationBot'
|
||||
# Notify new messages in-chat app (fiat exchange step) if at least X minutes has passed since the last chat message.
|
||||
CHAT_NOTIFICATION_TIMEGAP = 5
|
||||
|
||||
|
@ -21,7 +21,7 @@ class Telegram:
|
||||
context["tg_enabled"] = False
|
||||
|
||||
if user.robot.telegram_token is None:
|
||||
user.robot.telegram_token = token_urlsafe(15)
|
||||
user.robot.telegram_token = token_urlsafe()[:15]
|
||||
user.robot.save(update_fields=["telegram_token"])
|
||||
|
||||
context["tg_token"] = user.robot.telegram_token
|
||||
|
@ -176,10 +176,10 @@ class TestUtils(TestCase):
|
||||
client_enc_priv_key = r"-----BEGIN PGP PRIVATE KEY BLOCK-----\\xYYEZTWJ1xYJKwYBBAHaRw8BAQdAsfdKb90BurKniu+pBPBDHCkzg08S51W0\mUR0SKqLmdj+CQMICrS3TNCA/LHgxckC+iTUMxkqQJ9GpXWCDacx1rBQCztu\PDgUHNvWdcvW1wWVxU/aJaQLqBTtRVYkJTz332jrKvsSl/LnrfwmUfKgN4nG\Oc1MUm9ib1NhdHMgSUQgNTUyZGQxYTY2MWE3YWNhNGE0MWY4ODkxMGZmMzRh\YzNiMWFjODBiYjc3OTRlZDlmZDU1ZDhiNzZiOTdhYWQ5N8KMBBAWCgA+BYJl\NYnXBAsJBwgJkDc3tq7iCL/OAxUICgQWAAIBAhkBApsDAh4BFiEE7mIEuePQ\n8Tqye0QNze2ruIIv84AAORXAQD+0G30U+qvEsc48W3JTKmmmvT+3q+uXdGs\vMIuqoTWdQD/R+aGKvYXzwpyzGYInAAOj8WCXBcYWSOtXiw/oWNgEQHHiwRl\NYnXEgorBgEEAZdVAQUBAQdALJQh7exBNphr8gU0oY2ZfP/6Gse6Ryi3hM6+\LZsP2nwDAQgH/gkDCPPoYWyzm4mT4N/TDBF11GVq0xSEEcubFqjArFKyibRy\TDnB8+o8BlkRuGClcfRyKkR5/Rp1v5B0n1BuMsc8nY4Yg4BJv4KhsPfXRp4m\31zCeAQYFggAKgWCZTWJ1wmQNze2ruIIv84CmwwWIQTuYgS549CfxOrJ7RA3\N7au4gi/zgAAmhQA+wRtxO05FKFirSXuTj808F/mzF8u4Wz0kMNMzPUXvCj9\AQCHkxvHdvNHUyut4f7HkACnjI9M3+wGF69ArHL0u39/Aw==\=1hCT\-----END PGP PRIVATE KEY BLOCK-----"
|
||||
|
||||
# Example valid formatted GPG keys
|
||||
with open("api/tests/test_pub_key", "r") as file:
|
||||
with open("tests/robots/1/pub_key", "r") as file:
|
||||
# Read the contents of the file
|
||||
pub_key = file.read()
|
||||
with open("api/tests/test_enc_priv_key", "r") as file:
|
||||
with open("tests/robots/1/enc_priv_key", "r") as file:
|
||||
# Read the contents of the file
|
||||
enc_priv_key = file.read()
|
||||
|
||||
@ -203,10 +203,10 @@ class TestUtils(TestCase):
|
||||
|
||||
def test_verify_signed_message(self):
|
||||
# Call the verify_signed_message function with a mock public key and a mock signed message
|
||||
with open("api/tests/test_pub_key", "r") as file:
|
||||
with open("tests/robots/1/pub_key", "r") as file:
|
||||
# Read the contents of the file
|
||||
pub_key = file.read()
|
||||
with open("api/tests/test_signed_message", "r") as file:
|
||||
with open("tests/robots/1/signed_message", "r") as file:
|
||||
# Read the contents of the file
|
||||
signed_message = file.read()
|
||||
|
||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
1
tests/robots/1/b91_token
Normal file
1
tests/robots/1/b91_token
Normal file
@ -0,0 +1 @@
|
||||
qz*fp3CzNfK0Y2MWx;<Ke}2&S}ymduQyhjoJtIZE
|
1
tests/robots/1/nickname
Normal file
1
tests/robots/1/nickname
Normal file
@ -0,0 +1 @@
|
||||
MyopicRacket333
|
1
tests/robots/1/token
Normal file
1
tests/robots/1/token
Normal file
@ -0,0 +1 @@
|
||||
gUNa4xT98AA2AQWj4hsdCWFixOmvReu5If3R
|
82
tests/test_trade_pipeline.py
Normal file
82
tests/test_trade_pipeline.py
Normal file
@ -0,0 +1,82 @@
|
||||
import json
|
||||
|
||||
from decouple import config
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase
|
||||
|
||||
|
||||
class TradeTest(TestCase):
|
||||
su_pass = "12345678"
|
||||
su_name = config("ESCROW_USERNAME", cast=str, default="admin")
|
||||
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
User.objects.create_superuser(self.su_name, "super@user.com", self.su_pass)
|
||||
print("Super user created")
|
||||
|
||||
def test_login_superuser(self):
|
||||
path = "/coordinator/login/"
|
||||
data = {"username": self.su_name, "password": self.su_pass}
|
||||
response = self.client.post(path, data)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
def get_robot_auth(self, index):
|
||||
with open(f"tests/robots/{index}/b91_token", "r") as file:
|
||||
b91_token = file.read()
|
||||
with open(f"tests/robots/{index}/pub_key", "r") as file:
|
||||
pub_key = file.read()
|
||||
with open(f"tests/robots/{index}/enc_priv_key", "r") as file:
|
||||
enc_priv_key = file.read()
|
||||
|
||||
headers = {
|
||||
"HTTP_AUTHORIZATION": f"Token {b91_token} | Public {pub_key} | Private {enc_priv_key}"
|
||||
}
|
||||
return headers, pub_key, enc_priv_key
|
||||
|
||||
def create_robot(self, index):
|
||||
"""
|
||||
Creates the robots in /tests/robots/{index}/
|
||||
"""
|
||||
path = "/api/robot/"
|
||||
headers, pub_key, enc_priv_key = self.get_robot_auth(index)
|
||||
|
||||
response = self.client.get(path, **headers)
|
||||
data = json.loads(response.content.decode())
|
||||
|
||||
with open(f"tests/robots/{index}/nickname", "r") as file:
|
||||
expected_nickname = file.read()
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(
|
||||
data["nickname"],
|
||||
expected_nickname,
|
||||
f"Robot {index} created nickname is not MyopicRacket333",
|
||||
)
|
||||
self.assertEqual(
|
||||
data["public_key"], pub_key, "Returned public Kky does not match"
|
||||
)
|
||||
self.assertEqual(
|
||||
data["encrypted_private_key"],
|
||||
enc_priv_key,
|
||||
"Returned encrypted private key does not match",
|
||||
)
|
||||
self.assertEqual(
|
||||
len(data["tg_token"]), 15, "String is not exactly 15 characters long"
|
||||
)
|
||||
self.assertEqual(
|
||||
data["tg_bot_name"],
|
||||
config(
|
||||
"TELEGRAM_BOT_NAME", cast=str, default="RoboCoordinatorNotificationBot"
|
||||
),
|
||||
"Telegram bot name is not correct",
|
||||
)
|
||||
self.assertFalse(
|
||||
data["tg_enabled"], "The new robot's telegram seems to be enabled"
|
||||
)
|
||||
self.assertEqual(data["earned_rewards"], 0, "The new robot's rewards are not 0")
|
||||
|
||||
def test_create_robots(self):
|
||||
"""
|
||||
Creates two robots to test trades
|
||||
"""
|
||||
self.create_robot(index=1)
|
Loading…
Reference in New Issue
Block a user