-
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 #91 from xian-network/fix-state-stuff
Add depth to context
- Loading branch information
Showing
5 changed files
with
113 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@export | ||
def proxythis(con: str): | ||
return importlib.import_module(con).getthis() | ||
|
||
@export | ||
def nestedproxythis(con: str): | ||
return importlib.import_module(con).nested_exported() | ||
|
||
@export | ||
def noproxy(): | ||
return ctx.this, ctx.caller |
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,11 @@ | ||
@export | ||
def exported(): | ||
return ctx.this, ctx.caller | ||
|
||
@export | ||
def getthis(): | ||
return ctx.this, ctx.caller | ||
|
||
@export | ||
def nested_exported(): | ||
return exported() |
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,77 @@ | ||
import unittest | ||
from xian.processor import TxProcessor | ||
from contracting.client import ContractingClient | ||
from xian.services.simulator import Simulator | ||
from xian.constants import Constants | ||
import os | ||
import pathlib | ||
class MyTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
constants = Constants() | ||
self.c = ContractingClient(storage_home=constants.STORAGE_HOME) | ||
self.tx_processor = TxProcessor(client=self.c) | ||
self.stamp_calculator = Simulator() | ||
self.d = self.c.raw_driver | ||
self.d.flush_full() | ||
|
||
# Get the directory where the script is located | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Construct absolute paths for the contract files | ||
submission_contract_path = os.path.abspath( | ||
os.path.join( | ||
script_dir, | ||
"../../contracting/src/contracting/contracts/submission.s.py", | ||
) | ||
) | ||
|
||
with open(submission_contract_path) as f: | ||
contract = f.read() | ||
self.d.set_contract(name="submission", code=contract) | ||
|
||
def deploy_broken_stuff(self): | ||
# Get the directory where the script is located | ||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
proxythis_path = os.path.abspath( | ||
os.path.join( | ||
script_dir, | ||
"../../contracting/src/contracting/contracts/proxythis.py", | ||
) | ||
) | ||
with open(proxythis_path) as f: | ||
contract = f.read() | ||
|
||
self.c.submit( | ||
contract, | ||
name="con_proxythis", | ||
) | ||
|
||
self.proxythis = self.c.get_contract("con_proxythis") | ||
|
||
thistest2_path = os.path.abspath( | ||
os.path.join( | ||
script_dir, | ||
"../../contracting/src/contracting/contracts/thistest2.py", | ||
) | ||
) | ||
|
||
with open(thistest2_path) as f: | ||
contract = f.read() | ||
|
||
self.c.submit( | ||
contract, | ||
name="con_thistest2", | ||
) | ||
|
||
self.thistest2 = self.c.get_contract("con_thistest2") | ||
|
||
def test_submit(self): | ||
self.deploy_broken_stuff() | ||
self.assertEqual(self.proxythis.proxythis(con="con_thistest2", signer="address"), ("con_thistest2", "con_proxythis")) | ||
self.assertEqual(self.proxythis.noproxy(signer="address"), ("con_proxythis", "address")) | ||
self.assertEqual(self.proxythis.nestedproxythis(con="con_thistest2", signer="address"), ("con_thistest2", "con_proxythis")) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |