Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Daira Emma Hopwood <[email protected]>
  • Loading branch information
daira committed Oct 17, 2023
1 parent b0b19f6 commit 6f87191
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: tests

on: pull_request

jobs:
verify:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install gnome-keyring
run: sudo apt-get install gnome-keyring

- name: Install poetry
run: pip install --user poetry

- name: Install dependencies
run: poetry install --no-root

- name: Run tests
run: poetry run python -m unittest discover --verbose
18 changes: 18 additions & 0 deletions simtfl/bc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,21 @@ class BCProtocol:
Transaction: type[object] = BCTransaction
Context: type[object] = BCContext
Block: type[object] = BCBlock


import unittest

class TestBC(unittest.TestCase):
def test_basic(self):
ctx = BCContext()
issuance_tx0 = BCTransaction([], [10], 0, issuance=10)
assert ctx.add_if_valid(issuance_tx0)
genesis = BCBlock(None, 1, [issuance_tx0])
assert genesis.score == 1

issuance_tx1 = BCTransaction([], [6], -1, issuance=5)
spend_tx = BCTransaction([issuance_tx0.output(0)], [9], 1)
assert ctx.add_if_valid(issuance_tx1)
assert ctx.add_if_valid(spend_tx)
block1 = BCBlock(genesis, 1, [issuance_tx1, spend_tx])
assert block1.score == 2

0 comments on commit 6f87191

Please sign in to comment.