diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d055d41 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 diff --git a/simtfl/bc/__init__.py b/simtfl/bc/__init__.py index f17dc7c..5d70066 100644 --- a/simtfl/bc/__init__.py +++ b/simtfl/bc/__init__.py @@ -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