use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class WalletTest method createListOfCoinsWithAmount.
private List<Contract> createListOfCoinsWithAmount(List<Integer> values) throws Exception {
List<Contract> contracts = new ArrayList<>();
for (Integer value : values) {
Contract contract = createCoinWithAmount(String.valueOf(value), FIELD_NAME);
contracts.add(contract);
}
return contracts;
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class WalletTest method shouldSplitAndMergeOne.
@Test
public void shouldSplitAndMergeOne() throws Exception {
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(100, 200));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
// want to send 250
Wallet wallet = wallets.get(0);
Contract output = wallet.buildContractWithValue("amount", new Decimal(250));
output.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(output, true);
Contract contract = wallet.getContracts().get(0);
sealCheckTrace(contract, true);
assertEquals("50", contract.getState().getData().get("amount"));
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class WalletTest method shouldTransferAmountFromCoupleContracts.
@Test
public void shouldTransferAmountFromCoupleContracts() throws Exception {
Decimal valueToSend = new Decimal(70);
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(50, 45));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
assertEquals(1, wallets.size());
assertEquals(2, wallets.get(0).getContracts().size());
// gonna send 70 but I have 2 contracts (50, 45)
Wallet wallet = wallets.get(0);
Contract contract = wallet.buildContractWithValue(FIELD_NAME, valueToSend);
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
assertEquals(1, wallet.getContracts().size());
sealCheckTrace(contract, true);
TransactionPack tp = contract.getTransactionPack();
Contract contractToSend = new Contract(contract.seal(), tp);
contractToSend.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contractToSend, true);
assertEquals(valueToSend.intValue(), contractToSend.getStateData().getIntOrThrow(FIELD_NAME));
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class WalletTest method shouldTransferSumOf7.
@Test
public void shouldTransferSumOf7() throws Exception {
Decimal valueToSend = new Decimal(280);
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
assertEquals(1, wallets.size());
assertEquals(12, wallets.get(0).getContracts().size());
Wallet wallet = wallets.get(0);
Contract contract = wallet.buildContractWithValue(FIELD_NAME, valueToSend);
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contract, true);
assertEquals(6, wallet.getContracts().size());
TransactionPack tp = contract.getTransactionPack();
Contract contractToSend = new Contract(contract.seal(), tp);
contractToSend.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contractToSend, true);
assertEquals(valueToSend.intValue(), contractToSend.getStateData().getIntOrThrow(FIELD_NAME));
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class WalletTest method shouldTransferTheSameValue.
@Test
public void shouldTransferTheSameValue() throws Exception {
Decimal valueToSend = new Decimal(5);
List<Contract> listOfCoinsWithAmount = createListOfCoinsWithAmount(Arrays.asList(5));
List<Wallet> wallets = Wallet.determineWallets(listOfCoinsWithAmount);
assertEquals(1, wallets.size());
assertEquals(1, wallets.get(0).getContracts().size());
Wallet wallet = wallets.get(0);
Contract contract = wallet.buildContractWithValue(FIELD_NAME, valueToSend);
contract.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contract, true);
assertEquals(0, wallet.getContracts().size());
TransactionPack tp = contract.getTransactionPack();
Contract contractToSend = new Contract(contract.seal(), tp);
contractToSend.addSignerKeyFromFile(PRIVATE_KEY_PATH);
sealCheckTrace(contractToSend, true);
assertEquals(valueToSend.intValue(), contractToSend.getStateData().getIntOrThrow(FIELD_NAME));
}
Aggregations