use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class RemascTestRunner method start.
public void start() {
this.blockchain = this.builder.build();
((BlockChainImpl) this.blockchain).setNoValidation(true);
this.addedSiblings = new ArrayList<>();
List<Block> mainChainBlocks = new ArrayList<>();
this.blockchain.tryToConnect(this.genesis);
BlockExecutor blockExecutor = new BlockExecutor(new RskSystemProperties(), blockchain.getRepository(), null, blockchain.getBlockStore(), null);
for (int i = 0; i <= this.initialHeight; i++) {
int finalI = i;
List<SiblingElement> siblingsForCurrentHeight = this.siblingElements.stream().filter(siblingElement -> siblingElement.getHeightToBeIncluded() == finalI).collect(Collectors.toList());
List<BlockHeader> blockSiblings = new ArrayList<>();
// Going to add siblings
BlockDifficulty cummDifficulty = BlockDifficulty.ZERO;
if (siblingsForCurrentHeight.size() > 0) {
cummDifficulty = blockchain.getTotalDifficulty();
}
for (SiblingElement sibling : siblingsForCurrentHeight) {
RskAddress siblingCoinbase = TestUtils.randomAddress();
Block mainchainSiblingParent = mainChainBlocks.get(sibling.getHeight() - 1);
Block siblingBlock = createBlock(this.genesis, mainchainSiblingParent, PegTestUtils.createHash3(), siblingCoinbase, null, minerFee, Long.valueOf(i), this.txValue, this.txSigningKey, null);
blockSiblings.add(siblingBlock.getHeader());
blockchain.getBlockStore().saveBlock(siblingBlock, cummDifficulty.add(siblingBlock.getCumulativeDifficulty()), false);
this.addedSiblings.add(siblingBlock);
}
long txNonce = i;
RskAddress coinbase = TestUtils.randomAddress();
Block block = createBlock(this.genesis, this.blockchain.getBestBlock(), PegTestUtils.createHash3(), coinbase, blockSiblings, minerFee, txNonce, this.txValue, this.txSigningKey, null);
mainChainBlocks.add(block);
blockExecutor.executeAndFillAll(block, this.blockchain.getBestBlock());
block.seal();
ImportResult result = this.blockchain.tryToConnect(block);
System.out.println(result);
}
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class AddressBasedAuthorizerTest method isAuthorized.
@Test
public void isAuthorized() {
AddressBasedAuthorizer auth = new AddressBasedAuthorizer(Arrays.asList(ECKey.fromPrivate(BigInteger.valueOf(100L)), ECKey.fromPrivate(BigInteger.valueOf(101L)), ECKey.fromPrivate(BigInteger.valueOf(102L))), AddressBasedAuthorizer.MinimumRequiredCalculation.MAJORITY);
for (long n = 100L; n <= 102L; n++) {
Transaction mockedTx = mock(Transaction.class);
when(mockedTx.getSender()).thenReturn(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(n)).getAddress()));
Assert.assertTrue(auth.isAuthorized(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(n)).getAddress())));
Assert.assertTrue(auth.isAuthorized(mockedTx));
}
Assert.assertFalse(auth.isAuthorized(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(50L)).getAddress())));
Transaction mockedTx = mock(Transaction.class);
when(mockedTx.getSender()).thenReturn(new RskAddress(ECKey.fromPrivate(BigInteger.valueOf(50L)).getAddress()));
Assert.assertFalse(auth.isAuthorized(mockedTx));
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class VMComplexTest method test8.
// sha3_memSizeQuadraticCost31
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test8() {
int expectedGas = 354;
DataWord key1 = new DataWord(999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "60016103c020600055";
RskAddress contractAddrB = new RskAddress(contractAddr);
RskAddress callerAddrB = new RskAddress(callerAddr);
byte[] codeB = Hex.decode(code);
byte[] codeKey = HashUtil.keccak256(codeB);
AccountState accountState = new AccountState();
accountState.setCodeHash(codeKey);
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractAddrB);
Repository repository = pi.getRepository();
repository.createAccount(callerAddrB);
final BigInteger value = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
repository.addBalance(callerAddrB, new Coin(value));
repository.createAccount(contractAddrB);
repository.saveCode(contractAddrB, codeB);
repository.addStorageRow(contractAddrB, key1, value1);
// Play the program
VM vm = getSubject();
Program program = getProgram(codeB, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
System.out.println();
System.out.println("============ Results ============");
Coin balance = repository.getBalance(callerAddrB);
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
System.out.println("*** Contract Balance: " + balance);
// todo: assert caller balance after contract exec
repository.close();
assertEquals(expectedGas, program.getResult().getGasUsed());
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class VMComplexTest method test9.
// sha3_memSizeQuadraticCost32
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test9() {
int expectedGas = 356;
DataWord key1 = new DataWord(9999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "60016103e020600055";
RskAddress contractAddrB = new RskAddress(contractAddr);
RskAddress callerAddrB = new RskAddress(callerAddr);
byte[] codeB = Hex.decode(code);
byte[] codeKey = HashUtil.keccak256(codeB);
AccountState accountState = new AccountState();
accountState.setCodeHash(codeKey);
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractAddrB);
Repository repository = pi.getRepository();
repository.createAccount(callerAddrB);
final BigInteger value = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
repository.addBalance(callerAddrB, new Coin(value));
repository.createAccount(contractAddrB);
repository.saveCode(contractAddrB, codeB);
repository.addStorageRow(contractAddrB, key1, value1);
// Play the program
VM vm = getSubject();
Program program = getProgram(codeB, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
System.out.println();
System.out.println("============ Results ============");
Coin balance = repository.getBalance(callerAddrB);
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
System.out.println("*** Contract Balance: " + balance);
// todo: assert caller balance after contract exec
repository.close();
assertEquals(expectedGas, program.getResult().getGasUsed());
}
use of co.rsk.core.RskAddress in project rskj by rsksmart.
the class VMComplexTest method test7.
// sha3_memSizeQuadraticCost33
// TODO #POC9
@Ignore
// contract call quadratic memory use
@Test
public void test7() {
int expectedGas = 357;
DataWord key1 = new DataWord(999);
DataWord value1 = new DataWord(3);
// Set contract into Database
String callerAddr = "cd1722f3947def4cf144679da39c4c32bdc35681";
String contractAddr = "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6";
String code = "600161040020600055";
RskAddress contractAddrB = new RskAddress(contractAddr);
RskAddress callerAddrB = new RskAddress(callerAddr);
byte[] codeB = Hex.decode(code);
byte[] codeKey = HashUtil.keccak256(codeB);
AccountState accountState = new AccountState();
accountState.setCodeHash(codeKey);
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractAddrB);
Repository repository = pi.getRepository();
repository.createAccount(callerAddrB);
final BigInteger value = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935");
repository.addBalance(callerAddrB, new Coin(value));
repository.createAccount(contractAddrB);
repository.saveCode(contractAddrB, codeB);
repository.addStorageRow(contractAddrB, key1, value1);
// Play the program
VM vm = getSubject();
Program program = getProgram(codeB, pi);
try {
while (!program.isStopped()) vm.step(program);
} catch (RuntimeException e) {
program.setRuntimeFailure(e);
}
System.out.println();
System.out.println("============ Results ============");
Coin balance = repository.getBalance(callerAddrB);
System.out.println("*** Used gas: " + program.getResult().getGasUsed());
System.out.println("*** Contract Balance: " + balance);
// todo: assert caller balance after contract exec
repository.close();
assertEquals(expectedGas, program.getResult().getGasUsed());
}
Aggregations