def get_casper_ct(): import serpent global _casper_ct if not _casper_ct: _casper_ct = abi.ContractTranslator( serpent.mk_full_signature(open(casper_path).read())) return _casper_ct
def test_evm(): evm_code = serpent.compile(serpent_code) translator = abi.ContractTranslator( serpent.mk_full_signature(serpent_code)) data = translator.encode('main', [2, 5]) c = tester.Chain() x = c.contract(evm_code, l='evm') o = translator.decode('main', c.tx(tester.k0, x, 0, data)) assert o == [32]
from biblecoin import utils, abi, genesis_helpers, config from biblecoin.hybrid_casper.casper_initiating_transactions import mk_initializers, purity_checker_address, purity_checker_abi from biblecoin.hybrid_casper import consensus from biblecoin.messages import apply_transaction from biblecoin.tools.tester import a0 from viper import compiler import serpent import rlp ethereum_path = os.path.dirname(sys.modules['biblecoin'].__file__) casper_contract_path = '/'.join((ethereum_path, '..', 'casper', 'casper', 'contracts', 'simple_casper.v.py')) casper_code = open(casper_contract_path).read() casper_bytecode = compiler.compile(casper_code) casper_abi = compiler.mk_full_signature(casper_code) casper_translator = abi.ContractTranslator(casper_abi) purity_translator = abi.ContractTranslator(purity_checker_abi) code_template = """ ~calldatacopy(0, 0, 128) ~call(3000, 1, 0, 0, 128, 0, 32) return(~mload(0) == %s) """ # Get a genesis state which is primed for Casper def make_casper_genesis(alloc, epoch_length, withdrawal_delay, base_interest_factor, base_penalty_factor): # The Casper-specific config declaration casper_config = copy.deepcopy(config.default_config) casper_config['HOMESTEAD_FORK_BLKNUM'] = 0
# configure_logging(config_string=config_string) alloc = {} for i in range(9): alloc[utils.int_to_addr(i)] = {'balance': 1} alloc[t.a0] = {'balance': 10**22} alloc[t.a1] = {'balance': 10**22} genesis = casper_utils.make_casper_genesis(alloc, 5, 100, 0.02, 0.002) c = t.Chain(genesis=genesis) t.languages['viper'] = compiler.Compiler() t.gas_limit = 9999999 t.STARTGAS = 2000000 c.mine(1) EPOCH_LENGTH = c.chain.config['EPOCH_LENGTH'] ct = abi.ContractTranslator(purity_checker_abi) # Check that the RLP decoding library and the sig hashing library are "pure" assert utils.big_endian_to_int( c.tx(t.k0, purity_checker_address, 0, ct.encode('submit', [viper_rlp_decoder_address]))) == 1 assert utils.big_endian_to_int( c.tx(t.k0, purity_checker_address, 0, ct.encode('submit', [sig_hasher_address]))) == 1 casper = t.ABIContract(c, casper_abi, c.chain.config['CASPER_ADDRESS']) c.mine(1) # Begin the test print("Starting tests") # Initialize the first epoch
def mk_commit_tx(self, commit_msg): casper_ct = abi.ContractTranslator(casper_utils.casper_abi) commit_func = casper_ct.encode('commit', [commit_msg]) commit_tx = self.mk_transaction(self.chain.casper_address, 0, commit_func) return commit_tx
def mk_prepare_tx(self, prepare_msg): casper_ct = abi.ContractTranslator(casper_utils.casper_abi) prepare_func = casper_ct.encode('prepare', [prepare_msg]) prepare_tx = self.mk_transaction(to=self.chain.casper_address, value=0, data=prepare_func) return prepare_tx
def mk_logout(self, login_logout_msg): casper_ct = abi.ContractTranslator(casper_utils.casper_abi) logout_func = casper_ct.encode('logout', [login_logout_msg]) logout_tx = self.mk_transaction(self.chain.casper_address, data=logout_func) return logout_tx
def mk_deposit_tx(self, value, valcode_addr): casper_ct = abi.ContractTranslator(casper_utils.casper_abi) deposit_func = casper_ct.encode('deposit', [valcode_addr, self.coinbase]) deposit_tx = self.mk_transaction(self.chain.casper_address, value, deposit_func) return deposit_tx