Search in sources :

Example 6 with TransactionExecutor

use of org.ethereum.core.TransactionExecutor in project rskj by rsksmart.

the class CodeReplaceTest method replaceCodeTest2.

@Test
public void replaceCodeTest2() throws IOException, InterruptedException {
    // We test code replacement during initialization: this is forbitten.
    BigInteger nonce = config.getBlockchainConfig().getCommonConstants().getInitialNonce();
    BlockChainImpl blockchain = org.ethereum.core.ImportLightTest.createBlockchain(GenesisLoader.loadGenesis(config, nonce, getClass().getResourceAsStream("/genesis/genesis-light.json"), false));
    ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
    System.out.println("address: " + Hex.toHexString(sender.getAddress()));
    String asm = // (4b) header script v1
    "HEADER !0x01 !0x01 !0x00 " + // (5b) we attempt to replace the code
    "0x01 0x00 CODEREPLACE " + // (7b) Extract real code into address 0, skip first 12 bytes, copy 1 bytes
    "0x01 0x15 0x00 CODECOPY " + // (5b) offset 0, size 0x01, now return the first code
    "0x01 0x00  RETURN " + // (1b) REAL code to install
    "STOP ";
    EVMAssembler assembler = new EVMAssembler();
    byte[] code = assembler.assemble(asm);
    // Creates a contract
    Transaction tx1 = createTx(blockchain, sender, new byte[0], code);
    TransactionExecutor executor1 = executeTransaction(blockchain, tx1);
    // Now we can directly check the store and see the new code.
    Assert.assertTrue(executor1.getResult().getException() != null);
}
Also used : Transaction(org.ethereum.core.Transaction) BlockChainImpl(co.rsk.core.bc.BlockChainImpl) BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey) TransactionExecutor(org.ethereum.core.TransactionExecutor) EVMAssembler(co.rsk.asm.EVMAssembler) Test(org.junit.Test)

Aggregations

TransactionExecutor (org.ethereum.core.TransactionExecutor)6 Repository (org.ethereum.core.Repository)3 EVMAssembler (co.rsk.asm.EVMAssembler)2 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)2 BigInteger (java.math.BigInteger)2 Transaction (org.ethereum.core.Transaction)2 ECKey (org.ethereum.crypto.ECKey)2 Test (org.junit.Test)2 ProgramInvokeFactoryImpl (org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl)1