Skip to content

Commit

Permalink
Internal: reenable AVAX signature unit tests (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
odesenfans committed Jul 30, 2023
1 parent c8d1998 commit 1181c3b
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions tests/chains/test_avalanche.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
import pytest
import json

from aleph.chains.avalanche import AvalancheConnector
from aleph.schemas.pending_messages import parse_message, BasePendingMessage

TEST_MESSAGE = '{"chain": "AVA", "channel": "TEST", "sender": "5CGNMKCscqN2QNcT7Jtuz23ab7JUxh8wTEtXhECZLJn5vCGX", "type": "AGGREGATE", "time": 1601913525.231501, "item_content": "{\\"key\\":\\"test\\",\\"address\\":\\"5CGNMKCscqN2QNcT7Jtuz23ab7JUxh8wTEtXhECZLJn5vCGX\\",\\"content\\":{\\"a\\":1},\\"time\\":1601913525.231498}", "item_hash": "bfbc94fae6336d52ab65a4d907d399a0c16222bd944b3815faa08ad0e039ca1d", "signature": "{\\"curve\\": \\"sr25519\\", \\"data\\": \\"0x1ccefb257e89b4e3ecb7d71c8dc1d6e286290b9e32d2a11bf3f9d425c5790f4bff0b324dc774d20a13e38a340d1a48fada71fb0c68690c3adb8f0cc695b0eb83\\"}", "content": {"key": "test", "address": "5CGNMKCscqN2QNcT7Jtuz23ab7JUxh8wTEtXhECZLJn5vCGX", "content": {"a": 1}, "time": 1601913525.231498}}'


@pytest.mark.skip("TODO: investigate what's the correct format for the sender")
@pytest.mark.asyncio
async def test_verify_signature_real():
connector = AvalancheConnector()
message = json.loads(TEST_MESSAGE)
result = await connector.verify_signature(message)
assert result is True
@pytest.fixture
def avax_message() -> BasePendingMessage:
return parse_message(
{
"item_hash": "3c4d948a22c3d41b7d189555ee4a285cb490ec553f3d135cc3b2f0cfddf5c0f2",
"type": "POST",
"chain": "AVAX",
"sender": "X-avax14x5a42stua94l2vxjcag6c9ftd8ea0y8fltdwv",
"signature": "3WRUvPbp7euNQvxuhV2YaFUJHN2Xoo8yku67MTuhfk8bRvDQz6hysQrrkfyKweXSCDNzfjrYzd1PwhGWdTJGZAvuMPiEJvJ",
"item_type": "inline",
"item_content": '{"type":"avalanche","address":"X-avax14x5a42stua94l2vxjcag6c9ftd8ea0y8fltdwv","content":{"body":"This message was posted from the typescript-SDK test suite"},"time":1689163528.372}',
"time": 1689163528.372,
"channel": "TEST",
}
)


@pytest.mark.skip("TODO: AVAX tests are broken, update them to use the message models")
@pytest.mark.asyncio
async def test_verify_signature_nonexistent():
async def test_verify_signature_real(avax_message: BasePendingMessage):
connector = AvalancheConnector()
result = await connector.verify_signature(
{"chain": "CHAIN", "sender": "SENDER", "type": "TYPE", "item_hash": "ITEM_HASH"}
)
assert result is False
result = await connector.verify_signature(avax_message)
assert result is True


@pytest.mark.skip("TODO: AVAX tests are broken, update them to use the message models")
@pytest.mark.asyncio
async def test_verify_signature_bad_base58():
async def test_verify_signature_bad_base58(avax_message: BasePendingMessage):
connector = AvalancheConnector()
result = await connector.verify_signature(
{
"chain": "CHAIN",
"sender": "SENDER",
"type": "TYPE",
"item_hash": "ITEM_HASH",
"signature": "baba",
}
)
avax_message.signature = "baba"
result = await connector.verify_signature(avax_message)
assert result is False

0 comments on commit 1181c3b

Please sign in to comment.