Search in sources :

Example 6 with AccountInformationProvider

use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.

the class Web3ImplUnitTest method eth_getBalance.

@Test
public void eth_getBalance() {
    String id = "id";
    String addr = "0x0011223344556677880011223344556677889900";
    RskAddress expectedAddress = new RskAddress(addr);
    AccountInformationProvider aip = mock(AccountInformationProvider.class);
    when(retriever.getInformationProvider(eq(id))).thenReturn(aip);
    when(aip.getBalance(eq(expectedAddress))).thenReturn(new Coin(BigInteger.ONE));
    String result = target.eth_getBalance(addr, id);
    assertEquals("0x1", result);
}
Also used : Coin(co.rsk.core.Coin) RskAddress(co.rsk.core.RskAddress) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider) Test(org.junit.Test)

Example 7 with AccountInformationProvider

use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.

the class Web3ImplUnitTest method eth_getStorageAt.

@Test
public void eth_getStorageAt() {
    String id = "id";
    String addr = "0x0011223344556677880011223344556677889900";
    RskAddress expectedAddress = new RskAddress(addr);
    String storageIdx = "0x01";
    DataWord expectedIdx = DataWord.valueOf(stringHexToByteArray(storageIdx));
    AccountInformationProvider aip = mock(AccountInformationProvider.class);
    when(retriever.getInformationProvider(eq(id))).thenReturn(aip);
    when(aip.getStorageValue(eq(expectedAddress), eq(expectedIdx))).thenReturn(DataWord.ONE);
    String result = target.eth_getStorageAt(addr, storageIdx, id);
    assertEquals("0x0000000000000000000000000000000000000000000000000000000000000001", result);
}
Also used : RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider) Test(org.junit.Test)

Example 8 with AccountInformationProvider

use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.

the class Web3ImplUnitTest method eth_getStorageAtEmptyCell.

@Test
public void eth_getStorageAtEmptyCell() {
    String id = "id";
    String addr = "0x0011223344556677880011223344556677889900";
    RskAddress expectedAddress = new RskAddress(addr);
    String storageIdx = "0x01";
    DataWord expectedIdx = DataWord.valueOf(stringHexToByteArray(storageIdx));
    AccountInformationProvider aip = mock(AccountInformationProvider.class);
    when(retriever.getInformationProvider(eq(id))).thenReturn(aip);
    when(aip.getStorageValue(eq(expectedAddress), eq(expectedIdx))).thenReturn(null);
    String result = target.eth_getStorageAt(addr, storageIdx, id);
    assertEquals("0x0", result);
}
Also used : RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider) Test(org.junit.Test)

Example 9 with AccountInformationProvider

use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.

the class Web3InformationRetrieverTest method getState_latest.

@Test
public void getState_latest() {
    Block block = mock(Block.class);
    BlockHeader header = mock(BlockHeader.class);
    when(block.getHeader()).thenReturn(header);
    when(blockchain.getBestBlock()).thenReturn(block);
    RepositorySnapshot snapshot = mock(RepositorySnapshot.class);
    when(locator.findSnapshotAt(eq(header))).thenReturn(Optional.of(snapshot));
    AccountInformationProvider result = target.getInformationProvider("latest");
    assertEquals(snapshot, result);
}
Also used : RepositorySnapshot(co.rsk.db.RepositorySnapshot) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider) Test(org.junit.Test)

Example 10 with AccountInformationProvider

use of co.rsk.core.bc.AccountInformationProvider in project rskj by rsksmart.

the class Web3InformationRetrieverTest method getState_pending.

@Test
public void getState_pending() {
    PendingState aip = mock(PendingState.class);
    when(txPool.getPendingState()).thenReturn(aip);
    AccountInformationProvider result = target.getInformationProvider("pending");
    assertEquals(aip, result);
}
Also used : PendingState(co.rsk.core.bc.PendingState) AccountInformationProvider(co.rsk.core.bc.AccountInformationProvider) Test(org.junit.Test)

Aggregations

AccountInformationProvider (co.rsk.core.bc.AccountInformationProvider)11 RskAddress (co.rsk.core.RskAddress)7 Test (org.junit.Test)7 RepositorySnapshot (co.rsk.db.RepositorySnapshot)3 DataWord (org.ethereum.vm.DataWord)3 Coin (co.rsk.core.Coin)2 PendingState (co.rsk.core.bc.PendingState)1 BigInteger (java.math.BigInteger)1