use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class CliTest method testImportPrivateKey.
@Test
public void testImportPrivateKey() {
ECKey key = ECKeyFac.inst().create();
String[] args = { "-a", "import", Hex.toHexString(key.getPrivKeyBytes()) };
assertEquals(0, cli.call(args, CfgAion.inst()));
}
use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class BlockchainIntegrationTest method testSimpleBlockchainLoad.
// check that all accounts are loaded correctly
@Test
public void testSimpleBlockchainLoad() {
StandaloneBlockchain.Bundle b = (new StandaloneBlockchain.Builder()).withDefaultAccounts().build();
for (ECKey k : b.privateKeys) {
assertThat(b.bc.getRepository().getBalance(Address.wrap(k.getAddress()))).isNotEqualTo(BigInteger.ZERO);
}
assertThat(b.privateKeys.size()).isEqualTo(10);
}
use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class BlockPropagationTest method testIgnoreSameBlock.
@Test
public void testIgnoreSameBlock() {
List<ECKey> accounts = generateDefaultAccounts();
StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder().withValidatorConfiguration("simple").withDefaultAccounts(accounts).build();
AionBlock block = bundle.bc.createNewBlock(bundle.bc.getGenesis(), Collections.EMPTY_LIST, true);
assertThat(block.getNumber()).isEqualTo(1);
byte[] sender = HashUtil.h256("node1".getBytes());
byte[] receiver = HashUtil.h256("receiver".getBytes());
NodeMock senderMock = new NodeMock(sender, 1);
NodeMock receiverMock = new NodeMock(receiver, 0);
Map<Integer, INode> node = new HashMap<>();
node.put(1, senderMock);
node.put(2, receiverMock);
AtomicInteger times = new AtomicInteger();
P2pMock p2pMock = new P2pMock(node) {
@Override
public void send(int _nodeId, Msg _msg) {
if (_nodeId != receiverMock.getIdHash())
throw new RuntimeException("should only send to receiver");
times.getAndIncrement();
}
};
StandaloneBlockchain.Bundle anotherBundle = new StandaloneBlockchain.Builder().withValidatorConfiguration("simple").withDefaultAccounts(accounts).build();
assertThat(bundle.bc.genesis.getHash()).isEqualTo(anotherBundle.bc.genesis.getHash());
BlockPropagationHandler handler = new BlockPropagationHandler(1024, // NOTE: not the same blockchain that generated the block
anotherBundle.bc, p2pMock, anotherBundle.bc.getBlockHeaderValidator());
// block is processed
assertThat(handler.processIncomingBlock(senderMock.getIdHash(), block)).isEqualTo(BlockPropagationHandler.PropStatus.PROP_CONNECTED);
assertThat(handler.processIncomingBlock(senderMock.getIdHash(), block)).isEqualTo(BlockPropagationHandler.PropStatus.DROPPED);
assertThat(times.get()).isEqualTo(1);
}
use of org.aion.crypto.ECKey in project aion by aionnetwork.
the class ApiAion method sendTransaction.
public byte[] sendTransaction(ArgTxCall _params) {
Address from = _params.getFrom();
if (from == null || from.equals(Address.EMPTY_ADDRESS())) {
LOG.error("<send-transaction msg=invalid-from-address>");
return null;
}
ECKey key = this.getAccountKey(from.toString());
if (key == null) {
LOG.error("<send-transaction msg=account-not-found>");
return null;
}
try {
synchronized (pendingState) {
// TODO : temp set nrg & price to 1
byte[] nonce = (!_params.getNonce().equals(BigInteger.ZERO)) ? _params.getNonce().toByteArray() : pendingState.bestNonce(Address.wrap(key.getAddress())).toByteArray();
AionTransaction tx = new AionTransaction(nonce, _params.getTo(), _params.getValue().toByteArray(), _params.getData(), _params.getNrg(), _params.getNrgPrice());
tx.sign(key);
pendingState.addPendingTransaction(tx);
return tx.getHash();
}
} catch (Exception ex) {
return null;
}
}
Aggregations