def setUp(self): self.wallet = Wallet() self.client = ContractingClient() sync.submit_from_genesis_json_file(cilantro_ee.contracts.__path__[0] + '/genesis.json', client=ContractingClient()) processor.mint(self.wallet.vk.encode().hex(), 1000000000) self.currency = self.client.get_contract('currency') bal = self.currency.quick_read(variable='balances', key=self.wallet.vk.encode().hex()) self.assertEqual(bal, 1000000000)
def test_transaction_is_valid_complete_test_passes(self): w = Wallet() tx = build_transaction(wallet=w, processor='b' * 64, stamps=123, nonce=0, contract='currency', function='transfer', kwargs={ 'amount': 123, 'to': 'jeff' }) decoded = decode(tx) client = ContractingClient() client.flush() client.set_var(contract='currency', variable='balances', arguments=[w.verifying_key], value=1_000_000) client.set_var(contract='stamp_cost', variable='S', arguments=['value'], value=20_000) transaction.transaction_is_valid(transaction=decoded, expected_processor='b' * 64, client=client, nonces=self.driver)
def __init__(self, driver=ContractDriver(), debug=True): self.driver = driver self.client = ContractingClient(driver=driver) # All of this can be just derived from the blockchain driver without marking reads # Should marks on default be false? self.stamp_contract = self.client.get_contract('stamp_cost') self.reward_contract = self.client.get_contract('rewards') self.currency_contract = self.client.get_contract('currency') self.election_house = self.client.get_contract('election_house') self.foundation_contract = self.client.get_contract('foundation') self.masternodes_contract = self.client.get_contract('masternodes') self.delegates_contract = self.client.get_contract('delegates') assert self.stamp_contract is not None, 'Stamp contract not in state.' assert self.reward_contract is not None, 'Reward contract not in state.' assert self.currency_contract is not None, 'Currency contract not in state.' assert self.foundation_contract is not None, 'Foundation contract not in state.' assert self.masternodes_contract is not None, 'Masternodes not in state.' assert self.delegates_contract is not None, 'Delegates not in state.' self.log = get_logger('RWM') self.log.propagate = debug self.dust_exponent = 8
def setUp(self): self.c = ContractingClient(signer='stu') self.c.raw_driver.flush() with open('../../contracting/contracts/submission.s.py') as f: contract = f.read() self.c.raw_driver.set_contract( name='submission', code=contract, ) self.c.raw_driver.commit() submission = self.c.get_contract('submission') # submit erc20 clone with open('./test_contracts/pass_hash.s.py') as f: code = f.read() self.c.submit(code, name='pass_hash') with open('./test_contracts/test_pass_hash.s.py') as f: code = f.read() self.c.submit(code, name='test_pass_hash') self.pass_hash = self.c.get_contract('pass_hash') self.test_pass_hash = self.c.get_contract('test_pass_hash')
def test_secure_sec_cannot_connect_returns_none(self): authenticator = authentication.SocketAuthenticator( client=ContractingClient(), ctx=self.ctx) w = Wallet() w2 = Wallet() authenticator.add_verifying_key(w.verifying_key) authenticator.add_verifying_key(w2.verifying_key) authenticator.configure() async def get(): r = await router.secure_send(msg={'hello': 'there'}, service='something', wallet=w2, vk=w.verifying_key, ip='tcp://x', ctx=self.ctx) return r loop = asyncio.get_event_loop() res = loop.run_until_complete(get()) self.assertEqual(res, None) authenticator.authenticator.stop()
def setUp(self): self.client = ContractingClient() self.client.flush() with open('tad.py') as file: tad = file.read() with open('vault.py') as file: vault = file.read() with open('test_currency.py') as file: currency = file.read() with open('oracle.py') as file: oracle = file.read() with open('stake.py') as file: staking = file.read() self.client.submit(tad, name='tad_contract', constructor_args={'owner': 'vault_contract'}) self.client.submit(vault, name='vault_contract') self.client.submit(currency, name='currency') self.client.submit(oracle, name='oracle') self.client.submit(staking, name='staking') self.tad = self.client.get_contract('tad_contract') self.vault = self.client.get_contract('vault_contract') self.currency = self.client.get_contract('currency') self.oracle = self.client.get_contract('oracle') self.staking = self.client.get_contract('staking') self.tad.mint(amount=2000000, signer='vault_contract') self.tad.transfer(amount=2000000, to='testing_user', signer='vault_contract') self.oracle.set_price(number=0, new_price=1.0) # Probably not needed self.vault.change_any_state(key=('mint', 'DSR', 'owner'), new_value='staking')
def setUp(self): self.client = ContractingClient() f = open('./contracts/currency.s.py') self.client.submit(f.read(), 'currency') f.close() with open('./contracts/election_house.s.py') as f: contract = f.read() self.client.submit(contract, name='election_house') f = open('./contracts/elect_members.s.py') self.client.submit(f.read(), 'elect_members', constructor_args={'policy': 'masternodes'}) f.close() f = open('./contracts/stamp_cost.s.py') self.client.submit(f.read(), 'stamp_cost', owner='election_house', constructor_args={'initial_rate': 20_000}) f.close() self.election_house = self.client.get_contract('election_house') self.stamp_cost = self.client.get_contract(name='stamp_cost') self.election_house.register_policy(contract='stamp_cost') self.elect_members = self.client.get_contract('elect_members') self.currency = self.client.get_contract('currency')
def setUp(self): self.c = ContractingClient() self.c.flush() with open("../currency.s.py") as f: code = f.read() self.c.submit(code, name="currency", constructor_args={"vk": "sys"}) self.c.submit(code, name="con_rswp", constructor_args={"vk": "sys"}) self.currency = self.c.get_contract("currency") self.rswp = self.c.get_contract("con_rswp") with open("../con_basic_token.py") as f: code = f.read() self.c.submit(code, name="con_basic_token") self.basic_token = self.c.get_contract("con_basic_token") with open("con_staking_smart_epoch_multiasset.py") as f: code = f.read() self.c.submit(code, name="con_staking_smart_epoch") self.contract = self.c.get_contract("con_staking_smart_epoch") with open("con_staking_smart_epoch_multiasset.py") as f: code = f.read() self.c.submit(code, name="con_staking_smart_epoch_single_asset") self.contract_single_asset = self.c.get_contract( "con_staking_smart_epoch_single_asset" ) self.setupToken()
def setUp(self): self.c = ContractingClient() self.c.flush() with open('../currency.s.py') as f: code = f.read() self.c.submit(code, name='currency', constructor_args={'vk': 'sys'}) self.currency = self.c.get_contract('currency') with open('../con_basic_token.py') as f: code = f.read() self.c.submit(code, name='con_basic_token') self.basic_token = self.c.get_contract('con_basic_token') with open('con_staking.py') as f: code = f.read() self.c.submit(code, name='con_staking') self.contract = self.c.get_contract('con_staking') self.setupToken()
def setUp(self): self.c = ContractingClient() self.c.flush() with open("../currency.s.py") as f: contract = f.read() self.c.submit(contract, 'currency', constructor_args={"vk": "sys"}) self.c.submit(contract, 'con_token1', constructor_args={"vk": "sys"}) self.c.submit(contract, 'con_rswp', constructor_args={"vk": "sys"}) with open('../dex.py') as f: dex = f.read() self.c.submit(dex, 'dex') with open("../con_basic_token.py") as f: code = f.read() self.c.submit(code, name="con_basic_token") with open("con_liquidity_mining_smart_epoch.py") as f: code = f.read() self.c.submit(code, name="con_liquidity_mining_smart_epoch") self.contract = self.c.get_contract("con_liquidity_mining_smart_epoch") self.dex = self.c.get_contract('dex') self.rswp = self.c.get_contract('con_rswp') self.token1 = self.c.get_contract('con_token1') self.currency = self.c.get_contract("currency") self.basic_token = self.c.get_contract("con_basic_token") self.setupApprovals()
def setUp(self): self.ctx = zmq.asyncio.Context() self.ctx.max_sockets = 50_000 self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) ContractingClient().flush() MasterStorage().drop_collections()
def setUp(self): self.c = ContractingClient(signer='stu') self.c.flush() self.c.submit(coin) self.c.submit(pixel_game) self.pixel = self.c.get_contract('pixel_game')
def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() self.driver = ContractDriver(driver=InMemDriver()) asyncio.set_event_loop(self.loop) self.authenticator = authentication.SocketAuthenticator( client=ContractingClient(driver=self.driver), ctx=self.ctx)
def setUp(self): self.c = ContractingClient(signer='stu') self.c.raw_driver.flush() with open('../../contracting/contracts/submission.s.py') as f: contract = f.read() self.c.raw_driver.set_contract(name='submission', code=contract,) self.c.raw_driver.commit() submission = self.c.get_contract('submission') self.c.submit(too_many_writes) # submit erc20 clone with open('./test_contracts/thing.s.py') as f: code = f.read() self.c.submit(code, name='thing') with open('./test_contracts/foreign_thing.s.py') as f: code = f.read() self.c.submit(code, name='foreign_thing') self.thing = self.c.get_contract('thing') self.foreign_thing = self.c.get_contract('foreign_thing')
def setUp(self): self.client = ContractingClient() self.client.flush() with open('./contracts/election_house.s.py') as f: contract = f.read() self.client.submit(contract, name='election_house') self.election_house = self.client.get_contract('election_house') with open('./contracts/masternodes.s.py') as f: contract = f.read() self.client.submit( contract, name='masternodes', owner='election_house', constructor_args={ 'initial_masternodes': ['stu', 'raghu', 'alex', 'monica', 'steve', 'tejas'], 'initial_open_seats': 0 }) self.election_house.register_policy(contract='masternodes') self.masternodes = self.client.get_contract('masternodes')
def sync_genesis_contracts(genesis_path: str = 'genesis', extension: str = '*.s.py', exclude=['vkbook'], directory=os.path.dirname(__file__)): # Direct database writing of all contract files in the 'genesis' folder # direct_contracts = contracts_for_directory(direct_path, extension) # explicitly submit the submission contract submission_file = directory + '/submission.s.py' client = ContractingClient(submission_filename=submission_file) genesis_contracts = contracts_for_directory(genesis_path, extension, directory=directory) for contract in genesis_contracts: name = contract_name_from_file_path(contract) if name in exclude: continue if client.raw_driver.get_contract(name) is None: with open(contract) as f: code = f.read() client.submit(code, name=name)
def setUp(self): self.client = ContractingClient() self.client.flush() with open('dai.py') as file: dai = file.read() with open('vault.py') as file: vault = file.read() with open('test_currency.py') as file: currency = file.read() with open('oracle.py') as file: oracle = file.read() self.client.submit(dai, name='dai_contract', constructor_args={'owner': 'vault_contract'}) self.client.submit(vault, name='vault_contract') self.client.submit(currency, name='currency') self.client.submit(oracle, name='oracle') self.dai = self.client.get_contract('dai_contract') self.vault = self.client.get_contract('vault_contract') self.currency = self.client.get_contract('currency') self.oracle = self.client.get_contract('oracle') self.oracle.set_price(number=0, new_price=1.0) self.vault.change_any_state(key=('mint', 'DSR', 'owner'), new_value='sys') self.vault.change_any_state(key=(0, 'DSR', 'owner'), new_value='sys') self.vault.change_any_state(key=('currency', 'DSR', 'owner'), new_value='sys')
def setUp(self): self.c = ContractingClient(signer='stu') self.c.raw_driver.flush() with open('../../contracting/contracts/submission.s.py') as f: contract = f.read() self.c.raw_driver.set_contract(name='submission', code=contract) self.c.raw_driver.commit() # submit erc20 clone with open('./test_contracts/stubucks.s.py') as f: code = f.read() self.c.submit(code, name='stubucks') with open('./test_contracts/tejastokens.s.py') as f: code = f.read() self.c.submit(code, name='tejastokens') with open('./test_contracts/bastardcoin.s.py') as f: code = f.read() self.c.submit(code, name='bastardcoin') with open('./test_contracts/dynamic_importing.s.py') as f: code = f.read() self.c.submit(code, name='dynamic_importing') self.stubucks = self.c.get_contract('stubucks') self.tejastokens = self.c.get_contract('tejastokens') self.bastardcoin = self.c.get_contract('bastardcoin') self.dynamic_importing = self.c.get_contract('dynamic_importing')
def setUp(self): self.ctx = zmq.asyncio.Context() self.w = Wallet() masternodes = [ Wallet().verifying_key().hex(), Wallet().verifying_key().hex(), Wallet().verifying_key().hex(), ] delegates = [ Wallet().verifying_key().hex(), Wallet().verifying_key().hex(), Wallet().verifying_key().hex(), ] self.c = ContractingClient() self.c.flush() sync.submit_from_genesis_json_file(cilantro_ee.contracts.__path__[0] + '/genesis.json', client=self.c) sync.submit_node_election_contracts(initial_masternodes=masternodes, boot_mns=1, initial_delegates=delegates, boot_dels=1, client=self.c) self.s = SocketAuthenticator(ctx=self.ctx)
def setUp(self): self.ctx = zmq.asyncio.Context() self.loop = asyncio.new_event_loop() self.driver = ContractDriver(driver=InMemDriver()) self.client = ContractingClient(driver=self.driver) self.client.flush() asyncio.set_event_loop(self.loop)
def setUp(self): self.c = ContractingClient() self.c.flush() with open('./contracts/election_house.s.py') as f: contract = f.read() self.c.submit(contract, name='election_house') self.c.submit(rewards, owner='election_house') self.c.raw_driver.commit() self.election_house = self.c.get_contract('election_house') self.rewards = self.c.get_contract('rewards') self.election_house.register_policy(contract='rewards') self.c.submit(mock_nodes, name='masternodes', owner='election_house', constructor_args={'initial': ['v1', 'v2']}) self.c.submit(mock_nodes, name='delegates', owner='election_house', constructor_args={'initial': ['v3', 'v4', 'v5']}) self.election_house.register_policy(contract='masternodes') self.election_house.register_policy(contract='delegates')
def setUp(self): self.c = ContractingClient(signer='stu') self.c.raw_driver.flush() with open('../../contracting/contracts/submission.s.py') as f: contract = f.read() self.c.raw_driver.set_contract( name='submission', code=contract, ) self.c.raw_driver.commit() submission = self.c.get_contract('submission') # submit erc20 clone with open('./test_contracts/erc20_clone.s.py') as f: code = f.read() self.c.submit(code, name='erc20_clone') with open('./test_contracts/atomic_swaps.s.py') as f: code = f.read() self.c.submit(code, name='atomic_swaps') self.erc20_clone = self.c.get_contract('erc20_clone') self.atomic_swaps = self.c.get_contract('atomic_swaps')
def setUp(self): self.client = ContractingClient() self.client.flush() with open('./contracts/election_house.s.py') as f: contract = f.read() self.client.submit(contract, name='election_house') with open('./contracts/rewards.s.py') as f: contract = f.read() self.client.submit(contract, name='rewards') with open('./contracts/members.s.py') as f: contract = f.read() self.client.submit(contract, name='masternodes', owner='election_house', constructor_args={ 'initial_members': ['a', 'b'], 'candidate': 'elect_masters' }) self.client.submit(contract, name='delegates', owner='election_house', constructor_args={ 'initial_members': ['c', 'd', 'e', 'f'], 'candidate': 'elect_delegates' }) self.election_house = self.client.get_contract('election_house') self.election_house.register_policy(contract='masternodes') self.election_house.register_policy(contract='delegates') self.rewards = self.client.get_contract('rewards')
def submit_vkbook(vkbook_args: dict, overwrite=False): if not overwrite: c = ContractingClient() contract = c.get_contract('vkbook') if contract is not None: return submit_contract_with_construction_args('vkbook', args=vkbook_args)
def setUp(self): self.client = ContractingClient() self.client.flush() self.client.submit(currency_code, name="currency") self.client.submit(contract_code, name=CONTRACT_NAME) self.main_contract = self.client.get_contract(CONTRACT_NAME) self.currency_contract = self.client.get_contract("currency")
def setUp(self): self.c = ContractingClient(signer='stu') self.c.flush() with open('test_contracts/dater.py') as f: self.c.submit(f=f.read(), name='dater') self.dater = self.c.get_contract('dater')
def setUp(self): self.c = ContractingClient(signer='stu') self.c.flush() self.c.submit(con_module1) self.c.submit(con_all_in_one) self.c.submit(con_dynamic_import)
def setUp(self): self.client = ContractingClient() with open('./test_contracts/private_methods.s.py') as f: code = f.read() self.client.submit(code, name='private_methods') self.private_methods = self.client.get_contract('private_methods')
def setUp(self): self.client = ContractingClient() with open('./contracts/election_house.s.py') as f: contract = f.read() self.client.submit(contract, name='election_house') self.election_house = self.client.get_contract('election_house')
def test_multicast_sends_to_multiple(self): authenticator = authentication.SocketAuthenticator( client=ContractingClient(), ctx=self.ctx) w1 = Wallet() w2 = Wallet() w3 = Wallet() authenticator.add_verifying_key(w1.verifying_key) authenticator.add_verifying_key(w2.verifying_key) authenticator.add_verifying_key(w3.verifying_key) authenticator.configure() m1 = router.Router(socket_id='tcp://127.0.0.1:10000', ctx=self.ctx, linger=2000, poll_timeout=50, secure=True, wallet=w1) q1 = router.QueueProcessor() m1.add_service('something', q1) m2 = router.Router(socket_id='tcp://127.0.0.1:10001', ctx=self.ctx, linger=2000, poll_timeout=50, secure=True, wallet=w2) q2 = router.QueueProcessor() m2.add_service('something', q2) async def get(): peers = { w1.verifying_key: 'tcp://127.0.0.1:10000', w2.verifying_key: 'tcp://127.0.0.1:10001' } await router.secure_multicast(msg={'hello': 'there'}, service='something', wallet=w3, peer_map=peers, ctx=self.ctx) tasks = asyncio.gather( m1.serve(), m2.serve(), get(), stop_server(m1, 1), stop_server(m2, 1), ) loop = asyncio.get_event_loop() loop.run_until_complete(tasks) self.assertEqual(q1.q[0], {'hello': 'there'}) self.assertEqual(q2.q[0], {'hello': 'there'})