Esempio n. 1
0
    def apply_transaction(self, chain: Chain) -> None:

        # Instantiate the contract
        SimpleToken = self.w3.eth.contract(
            abi=self.contract_interface['abi'],
            bytecode=self.contract_interface['bin'])

        # Build transaction to deploy the contract
        w3_tx1 = SimpleToken.constructor().buildTransaction(W3_TX_DEFAULTS)

        tx = new_transaction(
            vm=chain.get_vm(),
            private_key=FUNDED_ADDRESS_PRIVATE_KEY,
            from_=FUNDED_ADDRESS,
            to=CREATE_CONTRACT_ADDRESS,
            amount=0,
            gas=FIRST_TX_GAS_LIMIT,
            data=decode_hex(w3_tx1['data']),
        )

        logging.debug('Applying Transaction {}'.format(tx))

        block, receipt, computation = chain.apply_transaction(tx)
        deployed_contract_address = computation.msg.storage_address

        assert computation.is_success

        # Interact with the deployed contract by calling the totalSupply() API
        simple_token = self.w3.eth.contract(
            address=Web3.toChecksumAddress(
                encode_hex(deployed_contract_address)),
            abi=self.contract_interface['abi'],
        )
        w3_tx2 = simple_token.functions.totalSupply().buildTransaction(
            W3_TX_DEFAULTS)

        tx2 = new_transaction(
            vm=chain.get_vm(),
            private_key=FUNDED_ADDRESS_PRIVATE_KEY,
            from_=FUNDED_ADDRESS,
            to=deployed_contract_address,
            amount=0,
            gas=SECOND_TX_GAS_LIMIT,
            data=decode_hex(w3_tx2['data']),
        )

        block, receipt, computation = chain.apply_transaction(tx2)

        assert computation.is_success
        assert to_int(computation.output) == EXPECTED_TOTAL_SUPPLY
Esempio n. 2
0
    def _deploy_simple_token(self, chain: MiningChain) -> None:
        # Instantiate the contract
        SimpleToken = self.w3.eth.contract(
            abi=self.contract_interface['abi'],
            bytecode=self.contract_interface['bin'])
        # Build transaction to deploy the contract
        w3_tx = SimpleToken.constructor().buildTransaction(W3_TX_DEFAULTS)
        tx = new_transaction(
            vm=chain.get_vm(),
            private_key=FUNDED_ADDRESS_PRIVATE_KEY,
            from_=FUNDED_ADDRESS,
            to=CREATE_CONTRACT_ADDRESS,
            amount=0,
            gas=FIRST_TX_GAS_LIMIT,
            data=decode_hex(w3_tx['data']),
        )
        logging.debug('Applying Transaction {}'.format(tx))
        block, receipt, computation = chain.apply_transaction(tx)
        # Keep track of deployed contract address
        self.deployed_contract_address = computation.msg.storage_address

        assert computation.is_success
        # Keep track of simple_token object
        self.simple_token = self.w3.eth.contract(
            address=Web3.toChecksumAddress(
                encode_hex(self.deployed_contract_address)),
            abi=self.contract_interface['abi'],
        )
Esempio n. 3
0
    def deploy_dos_contract(self, chain: MiningChain) -> None:
        # Instantiate the contract
        dos_contract = self.w3.eth.contract(
            abi=self.contract_interface['abi'],
            bytecode=self.contract_interface['bin'])

        # Build transaction to deploy the contract
        w3_tx1 = dos_contract.constructor().buildTransaction(W3_TX_DEFAULTS)

        tx = new_transaction(
            vm=chain.get_vm(),
            private_key=FUNDED_ADDRESS_PRIVATE_KEY,
            from_=FUNDED_ADDRESS,
            to=CREATE_CONTRACT_ADDRESS,
            amount=0,
            gas=FIRST_TX_GAS_LIMIT,
            data=decode_hex(w3_tx1['data']),
        )

        logging.debug('Applying Transaction {}'.format(tx))

        block, receipt, computation = chain.apply_transaction(tx)
        self.deployed_contract_address = computation.msg.storage_address

        assert computation.is_success

        # Interact with the deployed contract by calling the totalSupply() API ?????
        self.dos_contract = self.w3.eth.contract(
            address=Web3.toChecksumAddress(
                encode_hex(self.deployed_contract_address)),
            abi=self.contract_interface['abi'],
        )
Esempio n. 4
0
    def create_empty_contract_revert(self, chain: MiningChain) -> None:
        w3_tx5 = self.dos_contract.functions.createEmptyContractRevert(
        ).buildTransaction(W3_TX_DEFAULTS)

        tx5 = new_transaction(
            vm=chain.get_vm(),
            private_key=FUNDED_ADDRESS_PRIVATE_KEY,
            from_=FUNDED_ADDRESS,
            to=self.deployed_contract_address,
            amount=0,
            gas=FIFTH_TX_GAS_LIMIT,
            data=decode_hex(w3_tx5['data']),
        )

        block, receipt, computation = chain.apply_transaction(tx5)
Esempio n. 5
0
    def sstore_uint64_revert(self, chain: MiningChain) -> None:
        w3_tx4 = self.dos_contract.functions.storageEntropyRevert(
        ).buildTransaction(W3_TX_DEFAULTS)

        tx4 = new_transaction(
            vm=chain.get_vm(),
            private_key=FUNDED_ADDRESS_PRIVATE_KEY,
            from_=FUNDED_ADDRESS,
            to=self.deployed_contract_address,
            amount=0,
            gas=FORTH_TX_GAS_LIMIT,
            data=decode_hex(w3_tx4['data']),
        )

        block, receipt, computation = chain.apply_transaction(tx4)
Esempio n. 6
0
    def _erc_approve(self, addr2: str, chain: MiningChain) -> None:
        w3_tx = self.simple_token.functions.approve(
            addr2, TRANSFER_AMOUNT).buildTransaction(W3_TX_DEFAULTS)

        tx = new_transaction(
            vm=chain.get_vm(),
            private_key=FUNDED_ADDRESS_PRIVATE_KEY,
            from_=FUNDED_ADDRESS,
            to=self.deployed_contract_address,
            amount=0,
            gas=SECOND_TX_GAS_LIMIT,
            data=decode_hex(w3_tx['data']),
        )

        block, receipt, computation = chain.apply_transaction(tx)

        assert computation.is_success
        assert to_int(computation.output) == 1
Esempio n. 7
0
    def apply_transaction(self, chain: MiningChain) -> None:

        if self.config.to_address is None:
            to_address = generate_random_address()
        else:
            to_address = self.config.to_address

        tx = new_transaction(vm=chain.get_vm(),
                             private_key=FUNDED_ADDRESS_PRIVATE_KEY,
                             from_=FUNDED_ADDRESS,
                             to=to_address,
                             amount=100,
                             data=b'')

        logging.debug('Applying Transaction {}'.format(tx))

        block, receipt, computation = chain.apply_transaction(tx)

        logging.debug('Block {}'.format(block))
        logging.debug('Receipt {}'.format(receipt))
        logging.debug('Computation {}'.format(computation))