Search in sources :

Example 71 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RemascFeesPayer method logPayment.

private void logPayment(byte[] blockHash, Coin value, RskAddress toAddress, List<LogInfo> logs) {
    byte[] loggerContractAddress = this.contractAddress.getBytes();
    List<DataWord> topics = Arrays.asList(RemascContract.MINING_FEE_TOPIC, new DataWord(toAddress.getBytes()));
    byte[] data = RLP.encodeList(RLP.encodeElement(blockHash), RLP.encodeCoin(value));
    logs.add(new LogInfo(loggerContractAddress, topics, data));
}
Also used : LogInfo(org.ethereum.vm.LogInfo) DataWord(org.ethereum.vm.DataWord)

Example 72 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RemascStorageProvider method getRewardBalance.

public Coin getRewardBalance() {
    if (rewardBalance != null) {
        return rewardBalance;
    }
    DataWord address = new DataWord(REWARD_BALANCE_KEY.getBytes(StandardCharsets.UTF_8));
    DataWord value = this.repository.getStorageValue(this.contractAddress, address);
    if (value == null) {
        return Coin.ZERO;
    }
    return new Coin(value.getData());
}
Also used : Coin(co.rsk.core.Coin) DataWord(org.ethereum.vm.DataWord)

Example 73 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RemascStorageProvider method saveBrokenSelectionRule.

private void saveBrokenSelectionRule() {
    if (brokenSelectionRule == null) {
        return;
    }
    DataWord address = new DataWord(BROKEN_SELECTION_RULE_KEY.getBytes(StandardCharsets.UTF_8));
    byte[] bytes = new byte[1];
    bytes[0] = (byte) (this.brokenSelectionRule ? 1 : 0);
    this.repository.addStorageBytes(this.contractAddress, address, bytes);
}
Also used : DataWord(org.ethereum.vm.DataWord)

Example 74 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class RemascStorageProvider method saveRewardBalance.

private void saveRewardBalance() {
    if (rewardBalance == null) {
        return;
    }
    DataWord address = new DataWord(REWARD_BALANCE_KEY.getBytes(StandardCharsets.UTF_8));
    this.repository.addStorageRow(this.contractAddress, address, new DataWord(this.rewardBalance.getBytes()));
}
Also used : DataWord(org.ethereum.vm.DataWord)

Example 75 with DataWord

use of org.ethereum.vm.DataWord in project rskj by rsksmart.

the class BridgeStorageProviderTest method getNewFederation_nullBytes.

@Test
public void getNewFederation_nullBytes() throws IOException {
    List<Integer> storageBytesCalls = new ArrayList<>();
    List<Integer> deserializeCalls = new ArrayList<>();
    Context contextMock = mock(Context.class);
    PowerMockito.mockStatic(BridgeSerializationUtils.class);
    Repository repositoryMock = mock(Repository.class);
    BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getBlockchainConfig().getCommonConstants().getBridgeConstants());
    Whitebox.setInternalState(storageProvider, "btcContext", contextMock);
    when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> {
        storageBytesCalls.add(0);
        RskAddress contractAddress = invocation.getArgumentAt(0, RskAddress.class);
        DataWord address = invocation.getArgumentAt(1, DataWord.class);
        // Make sure the bytes are get from the correct address in the repo
        Assert.assertTrue(Arrays.equals(new byte[] { (byte) 0xaa, (byte) 0xbb, (byte) 0xcc, (byte) 0xdd }, contractAddress.getBytes()));
        Assert.assertEquals(new DataWord("newFederation".getBytes(StandardCharsets.UTF_8)), address);
        return null;
    });
    PowerMockito.when(BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(Context.class))).then((InvocationOnMock invocation) -> {
        deserializeCalls.add(0);
        return null;
    });
    Assert.assertEquals(null, storageProvider.getNewFederation());
    Assert.assertEquals(null, storageProvider.getNewFederation());
    // 2 for the calls to getStorageBytes
    Assert.assertEquals(2, storageBytesCalls.size());
    // 2 for the calls to getStorageBytes
    Assert.assertEquals(0, deserializeCalls.size());
}
Also used : BigInteger(java.math.BigInteger) Repository(org.ethereum.core.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DataWord (org.ethereum.vm.DataWord)133 Test (org.junit.Test)88 Repository (org.ethereum.core.Repository)41 RskAddress (co.rsk.core.RskAddress)25 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)22 BigInteger (java.math.BigInteger)19 LogInfo (org.ethereum.vm.LogInfo)17 HashMapDB (org.ethereum.datasource.HashMapDB)14 Program (org.ethereum.vm.program.Program)13 Stack (org.ethereum.vm.program.Stack)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 RepositoryImpl (co.rsk.db.RepositoryImpl)9 ContractDetails (org.ethereum.db.ContractDetails)9 Trie (co.rsk.trie.Trie)8 CallTransaction (org.ethereum.core.CallTransaction)8 TrieImpl (co.rsk.trie.TrieImpl)7 TrieStore (co.rsk.trie.TrieStore)7 Coin (co.rsk.core.Coin)5