Search in sources :

Example 6 with ProgramSubtrace

use of co.rsk.rpc.modules.trace.ProgramSubtrace in project rskj by rsksmart.

the class RemascFeesPayerTest method payMiningFees.

@Test
public void payMiningFees() {
    // Setup objects
    Repository repositoryMock = Mockito.mock(Repository.class);
    RemascFeesPayer feesPayer = new RemascFeesPayer(repositoryMock, PrecompiledContracts.REMASC_ADDR);
    byte[] blockHash = { 0x1, 0x2 };
    Coin value = Coin.valueOf(7L);
    RskAddress toAddress = new RskAddress("6c386a4b26f73c802f34673f7248bb118f97424a");
    List<LogInfo> logs = new ArrayList<>();
    // Do call
    feesPayer.payMiningFees(blockHash, value, toAddress, logs);
    Assert.assertEquals(1, feesPayer.getSubtraces().size());
    ProgramSubtrace subtrace = feesPayer.getSubtraces().get(0);
    Assert.assertEquals(DataWord.valueOf(PrecompiledContracts.REMASC_ADDR.getBytes()), subtrace.getInvokeData().getCallerAddress());
    Assert.assertEquals(DataWord.valueOf(toAddress.getBytes()), subtrace.getInvokeData().getOwnerAddress());
    Assert.assertEquals(DataWord.valueOf(value.getBytes()), subtrace.getInvokeData().getCallValue());
    Assert.assertEquals(1, logs.size());
    // Assert address that made the log
    LogInfo result = logs.get(0);
    Assert.assertArrayEquals(PrecompiledContracts.REMASC_ADDR.getBytes(), result.getAddress());
    // Assert log topics
    Assert.assertEquals(2, result.getTopics().size());
    Assert.assertEquals("000000000000000000000000000000006d696e696e675f6665655f746f706963", result.getTopics().get(0).toString());
    Assert.assertEquals("0000000000000000000000006c386a4b26f73c802f34673f7248bb118f97424a", result.getTopics().get(1).toString());
    // Assert log data
    Assert.assertNotNull(result.getData());
    List<RLPElement> rlpData = RLP.decode2(result.getData());
    Assert.assertEquals(1, rlpData.size());
    RLPList dataList = (RLPList) rlpData.get(0);
    Assert.assertEquals(2, dataList.size());
    Assert.assertArrayEquals(blockHash, dataList.get(0).getRLPData());
    Assert.assertEquals(value, RLP.parseCoin(dataList.get(1).getRLPData()));
    // Assert repository calls are made right
    verify(repositoryMock, times(1)).addBalance(PrecompiledContracts.REMASC_ADDR, value.negate());
    verify(repositoryMock, times(1)).addBalance(toAddress, value);
}
Also used : Coin(co.rsk.core.Coin) Repository(org.ethereum.core.Repository) LogInfo(org.ethereum.vm.LogInfo) ProgramSubtrace(co.rsk.rpc.modules.trace.ProgramSubtrace) RLPElement(org.ethereum.util.RLPElement) RskAddress(co.rsk.core.RskAddress) ArrayList(java.util.ArrayList) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Aggregations

ProgramSubtrace (co.rsk.rpc.modules.trace.ProgramSubtrace)6 Coin (co.rsk.core.Coin)3 RskAddress (co.rsk.core.RskAddress)3 TransferInvoke (org.ethereum.vm.program.invoke.TransferInvoke)3 Repository (org.ethereum.core.Repository)2 DataWord (org.ethereum.vm.DataWord)2 ProgramResult (org.ethereum.vm.program.ProgramResult)2 ArrayList (java.util.ArrayList)1 RLPElement (org.ethereum.util.RLPElement)1 RLPList (org.ethereum.util.RLPList)1 LogInfo (org.ethereum.vm.LogInfo)1 ProgramTrace (org.ethereum.vm.trace.ProgramTrace)1 SummarizedProgramTrace (org.ethereum.vm.trace.SummarizedProgramTrace)1 Test (org.junit.Test)1