-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from xian-network/driver-tx-specific-writes
driver - transaction specific writes
- Loading branch information
Showing
5 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import importlib | ||
from unittest import TestCase | ||
from contracting.stdlib.bridge.time import Datetime | ||
from contracting.client import ContractingClient | ||
from contracting.storage.driver import Driver | ||
|
||
|
||
class TestTransactionWrites(TestCase): | ||
def setUp(self): | ||
self.c = ContractingClient() | ||
self.c.flush() | ||
|
||
with open("./test_contracts/currency.s.py") as f: | ||
contract = f.read() | ||
|
||
self.c.submit(contract, name="currency") | ||
|
||
self.c.executor.driver.commit() | ||
|
||
def tearDown(self): | ||
self.c.raw_driver.flush_full() | ||
|
||
def test_transfers(self): | ||
self.c.set_var( | ||
contract="currency", variable="balances", arguments=["bill"], value=200 | ||
) | ||
res3 = self.c.executor.execute( | ||
contract_name="currency", | ||
function_name="transfer", | ||
kwargs={"to": "someone", "amount": 100}, | ||
stamps=1000, | ||
sender="bill", | ||
) | ||
self.assertEquals(res3["writes"], self.c.executor.driver.pending_writes) | ||
res2 = self.c.executor.execute( | ||
contract_name="currency", | ||
function_name="transfer", | ||
kwargs={"to": "someone", "amount": 100}, | ||
stamps=1000, | ||
sender="bill", | ||
) | ||
|
||
self.assertEquals(res2["writes"], self.c.executor.driver.pending_writes) | ||
# This operation will raise an exception, so will not make any writes. | ||
res3 = self.c.executor.execute( | ||
contract_name="currency", | ||
function_name="transfer", | ||
kwargs={"to": "someone", "amount": 100}, | ||
stamps=1000, | ||
sender="bill", | ||
) | ||
self.assertEquals(res3["writes"], {}) | ||
|
||
|
||
if __name__ == "__main__": | ||
import unittest | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters