diff --git a/xcat/cli.py b/xcat/cli.py index 16248dd..e04c20e 100644 --- a/xcat/cli.py +++ b/xcat/cli.py @@ -181,7 +181,10 @@ def find_role(contract): else: return 'initiator' else: - return 'fulfiller' + if protocol.is_myaddr(contract.fulfiller): + return 'fulfiller' + else: + raise ValueError('You are not a participant in this contract.') def checktrade(tradeid): diff --git a/xcat/tests/test_cli.py b/xcat/tests/test_cli.py index 92ae1d5..8bf0ecd 100644 --- a/xcat/tests/test_cli.py +++ b/xcat/tests/test_cli.py @@ -70,6 +70,21 @@ class TestCLI(unittest.TestCase): self.assertEqual(res, 'fulfiller') + @mock.patch('xcat.cli.Protocol') + def test_find_role_error(self, mock_protocol): + mock_protocol().is_myaddr = lambda k: k == 'me' + + test_contract = mock.MagicMock() + test_contract.initiator = 'you' + test_contract.fulfiller = 'you' + + with self.assertRaises(ValueError) as context: + cli.find_role(test_contract) + + self.assertTrue( + 'You are not a participant in this contract.' + in str(context.exception)) + def test_checktrade(self): pass