Search in sources :

Example 21 with Network

use of com.google.api.ads.admanager.axis.v202205.Network in project universa by UniversaBlockchain.

the class MainTest method testGetContractAPIforManyActive.

@Test
public void testGetContractAPIforManyActive() throws Exception {
    // init network in permanet mode
    List<Main> mm = new ArrayList<>();
    for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), "_permanet", false));
    Main main = mm.get(0);
    main.config.setIsFreeRegistrationsAllowedFromYaml(true);
    main.config.getKeysWhiteList().add(TestKeys.publicKey(20));
    Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
    assertTrue(main.config.isPermanetMode());
    for (int i = 1; i < 4; i++) assertTrue(mm.get(i).config.isPermanetMode());
    // try cancel permanet mode
    main.config.setPermanetMode(false);
    assertTrue(main.config.isPermanetMode());
    Set<PrivateKey> issuerPrivateKeys = new HashSet<>(asList(TestKeys.privateKey(1)));
    Set<PublicKey> ownerPublicKeys = new HashSet<>(asList(TestKeys.publicKey(2)));
    Set<PrivateKey> issuerPrivateKeys2 = new HashSet<>(asList(TestKeys.privateKey(2)));
    List<Contract> splits = new ArrayList<>();
    Integer amountTokens = 1000;
    Contract tokenContract = ContractsService.createTokenContract(issuerPrivateKeys, ownerPublicKeys, new BigDecimal("1000"));
    tokenContract.check();
    tokenContract.traceErrors();
    HashId origin = tokenContract.getId();
    ItemResult itemResult = client.register(tokenContract.getPackedTransaction(), 5000);
    System.out.println("tokenContract : " + itemResult + " = " + amountTokens.toString());
    assertEquals(ItemState.APPROVED, itemResult.state);
    for (Integer i = 1; i < 41; i++) {
        Contract contractRemainder = ContractsService.createSplit(tokenContract, new BigDecimal(i), "amount", issuerPrivateKeys2, true);
        Contract contractSplit = contractRemainder.getNew().get(0);
        amountTokens -= i;
        splits.add(contractSplit);
        itemResult = client.register(contractRemainder.getPackedTransaction(), 5000);
        System.out.println("contractRemainder : " + itemResult + " = " + amountTokens.toString());
        assertEquals(ItemState.APPROVED, itemResult.state);
        assertEquals(amountTokens.toString(), contractRemainder.getStateData().get("amount").toString());
        assertEquals(i.toString(), contractSplit.getStateData().get("amount").toString());
        assertEquals(ItemState.REVOKED, main.node.waitItem(tokenContract.getId(), 5000).state);
        assertEquals(ItemState.APPROVED, main.node.waitItem(contractRemainder.getId(), 5000).state);
        assertEquals(ItemState.APPROVED, main.node.waitItem(contractSplit.getId(), 5000).state);
        tokenContract = contractRemainder;
    }
    // check getContract (default limit 100)
    Binder result = client.getContract(origin);
    List<byte[]> allKeepingIds = result.getListOrThrow("contractIds");
    assertFalse(result.containsKey("packedContract"));
    assertEquals(allKeepingIds.size(), splits.size() + 1);
    final HashId hash = tokenContract.getId();
    assertTrue(allKeepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id)));
    splits.forEach(s -> assertTrue(allKeepingIds.stream().anyMatch(id -> Arrays.equals(s.getId().getDigest(), id))));
    // check getContract with limit
    result = client.getContract(origin, 10);
    List<byte[]> keepingIds = result.getListOrThrow("contractIds");
    assertFalse(result.containsKey("packedContract"));
    assertEquals(keepingIds.size(), 10);
    assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id)));
    for (int i = splits.size() - 1; i > splits.size() - 10; i--) {
        final HashId hashSplit = splits.get(i).getId();
        assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hashSplit.getDigest(), id)));
    }
    // set limit in node config
    mm.forEach(x -> x.config.setQueryContractsLimit(20));
    // check getContract (default limit 100)
    result = client.getContract(origin);
    keepingIds = result.getListOrThrow("contractIds");
    assertFalse(result.containsKey("packedContract"));
    assertEquals(keepingIds.size(), 20);
    assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id)));
    for (int i = splits.size() - 1; i > splits.size() - 20; i--) {
        final HashId hashSplit = splits.get(i).getId();
        assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hashSplit.getDigest(), id)));
    }
    // check getContract with limit
    result = client.getContract(origin, 30);
    keepingIds = result.getListOrThrow("contractIds");
    assertFalse(result.containsKey("packedContract"));
    assertEquals(keepingIds.size(), 20);
    assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hash.getDigest(), id)));
    for (int i = splits.size() - 1; i > splits.size() - 20; i--) {
        final HashId hashSplit = splits.get(i).getId();
        assertTrue(keepingIds.stream().anyMatch(id -> Arrays.equals(hashSplit.getDigest(), id)));
    }
    mm.forEach(x -> x.shutdown());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) SecureLoanHelper(com.icodici.universa.contract.helpers.SecureLoanHelper) TimeoutException(java.util.concurrent.TimeoutException) BigDecimal(java.math.BigDecimal) com.icodici.universa.contract.permissions(com.icodici.universa.contract.permissions) java.net(java.net) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BossBiMapper(net.sergeych.biserializer.BossBiMapper) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Duration(java.time.Duration) Path(java.nio.file.Path) Role(com.icodici.universa.contract.roles.Role) LogPrinter(net.sergeych.utils.LogPrinter) ListRole(com.icodici.universa.contract.roles.ListRole) com.icodici.universa.contract.services(com.icodici.universa.contract.services) PreparedStatement(java.sql.PreparedStatement) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) DbPool(com.icodici.db.DbPool) ZoneId(java.time.ZoneId) EncryptionError(com.icodici.crypto.EncryptionError) MatcherAssert(org.hamcrest.MatcherAssert) Crc32(com.icodici.crypto.digest.Crc32) PooledDb(com.icodici.db.PooledDb) Compound(com.icodici.universa.contract.helpers.Compound) EscrowHelper(com.icodici.universa.contract.helpers.EscrowHelper) Matchers.is(org.hamcrest.Matchers.is) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) ChronoField(java.time.temporal.ChronoField) NonNull(org.checkerframework.checker.nullness.qual.NonNull) java.util(java.util) com.icodici.universa.node(com.icodici.universa.node) net.sergeych.tools(net.sergeych.tools) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) PublicKey(com.icodici.crypto.PublicKey) com.icodici.universa.contract(com.icodici.universa.contract) com.icodici.universa.node2.network(com.icodici.universa.node2.network) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) PrivateKey(com.icodici.crypto.PrivateKey) Files(java.nio.file.Files) Semaphore(java.util.concurrent.Semaphore) KeyAddress(com.icodici.crypto.KeyAddress) Matchers(org.hamcrest.Matchers) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) com.icodici.universa(com.icodici.universa) TimeUnit(java.util.concurrent.TimeUnit) Db(com.icodici.db.Db) ChronoUnit(java.time.temporal.ChronoUnit) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) RoleLink(com.icodici.universa.contract.roles.RoleLink) Assert(org.junit.Assert) Boss(net.sergeych.boss.Boss) PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) BigDecimal(java.math.BigDecimal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 22 with Network

use of com.google.api.ads.admanager.axis.v202205.Network in project universa by UniversaBlockchain.

the class MainTest method testSwapSplitJoin_Api2.

@Test
public void testSwapSplitJoin_Api2() throws Exception {
    List<Main> mm = new ArrayList<>();
    for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), false));
    Main main = mm.get(0);
    main.config.setIsFreeRegistrationsAllowedFromYaml(true);
    Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
    Set<PrivateKey> user1PrivateKeySet = new HashSet<>(asList(TestKeys.privateKey(1)));
    Set<PrivateKey> user2PrivateKeySet = new HashSet<>(asList(TestKeys.privateKey(2)));
    Set<PublicKey> user1PublicKeySet = user1PrivateKeySet.stream().map(prv -> prv.getPublicKey()).collect(Collectors.toSet());
    Set<PublicKey> user2PublicKeySet = user2PrivateKeySet.stream().map(prv -> prv.getPublicKey()).collect(Collectors.toSet());
    Contract contractTOK92 = ContractsService.createTokenContract(user1PrivateKeySet, user1PublicKeySet, new BigDecimal("100"), new BigDecimal("0.0001"));
    Contract contractTOK93 = ContractsService.createTokenContract(user2PrivateKeySet, user2PublicKeySet, new BigDecimal("100"), new BigDecimal("0.001"));
    contractTOK92.seal();
    contractTOK92.check();
    contractTOK92.traceErrors();
    ItemResult itemResult = client.register(contractTOK92.getPackedTransaction(), 5000);
    assertEquals(ItemState.APPROVED, itemResult.state);
    contractTOK93.seal();
    contractTOK93.check();
    contractTOK93.traceErrors();
    itemResult = client.register(contractTOK93.getPackedTransaction(), 5000);
    assertEquals(ItemState.APPROVED, itemResult.state);
    System.out.println("--- tokens created ---");
    // TOK92: 100 - 8.02 = 91.98
    Contract user1CoinsSplit = ContractsService.createSplit(contractTOK92, new BigDecimal("8.02"), "amount", user1PrivateKeySet);
    Contract user1CoinsSplitToUser2 = user1CoinsSplit.getNew().get(0);
    // TOK93: 100 - 10.01 = 89.99
    Contract user2CoinsSplit = ContractsService.createSplit(contractTOK93, new BigDecimal("10.01"), "amount", user2PrivateKeySet);
    Contract user2CoinsSplitToUser1 = user2CoinsSplit.getNew().get(0);
    user1CoinsSplitToUser2.check();
    user1CoinsSplitToUser2.traceErrors();
    user2CoinsSplitToUser1.check();
    user2CoinsSplitToUser1.traceErrors();
    // exchanging the contracts
    System.out.println("--- procedure for exchange of contracts ---");
    // Step one
    Contract swapContract;
    swapContract = ContractsService.startSwap(user1CoinsSplitToUser2, user2CoinsSplitToUser1, user1PrivateKeySet, user2PublicKeySet, false);
    // Step two
    ContractsService.signPresentedSwap(swapContract, user2PrivateKeySet);
    // Final step
    ContractsService.finishSwap(swapContract, user1PrivateKeySet);
    user1CoinsSplit.seal();
    user2CoinsSplit.seal();
    swapContract.getNewItems().clear();
    swapContract.addNewItems(user1CoinsSplit, user2CoinsSplit);
    swapContract.seal();
    swapContract.check();
    swapContract.traceErrors();
    System.out.println("Transaction contract for swapping is valid: " + swapContract.isOk());
    // now emulate sending transaction pack through network
    swapContract = Contract.fromPackedTransaction(swapContract.getPackedTransaction());
    main.node.registerItem(swapContract);
    assertEquals(ItemState.APPROVED, main.node.waitItem(swapContract.getId(), 5000).state);
    assertEquals(ItemState.APPROVED, main.node.waitItem(user1CoinsSplit.getId(), 5000).state);
    assertEquals(ItemState.APPROVED, main.node.waitItem(user2CoinsSplit.getId(), 5000).state);
    assertEquals(ItemState.APPROVED, main.node.waitItem(user1CoinsSplitToUser2.getId(), 5000).state);
    assertEquals(ItemState.APPROVED, main.node.waitItem(user2CoinsSplitToUser1.getId(), 5000).state);
    assertEquals(ItemState.REVOKED, main.node.waitItem(contractTOK92.getId(), 5000).state);
    assertEquals(ItemState.REVOKED, main.node.waitItem(contractTOK93.getId(), 5000).state);
    assertEquals("8.02", user1CoinsSplitToUser2.getStateData().getStringOrThrow("amount"));
    assertEquals("10.01", user2CoinsSplitToUser1.getStateData().getStringOrThrow("amount"));
    assertFalse(user1CoinsSplitToUser2.getOwner().isAllowedForKeys(user1PublicKeySet));
    assertTrue(user1CoinsSplitToUser2.getOwner().isAllowedForKeys(user2PublicKeySet));
    assertTrue(user2CoinsSplitToUser1.getOwner().isAllowedForKeys(user1PublicKeySet));
    assertFalse(user2CoinsSplitToUser1.getOwner().isAllowedForKeys(user2PublicKeySet));
    mm.forEach(x -> x.shutdown());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) SecureLoanHelper(com.icodici.universa.contract.helpers.SecureLoanHelper) TimeoutException(java.util.concurrent.TimeoutException) BigDecimal(java.math.BigDecimal) com.icodici.universa.contract.permissions(com.icodici.universa.contract.permissions) java.net(java.net) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BossBiMapper(net.sergeych.biserializer.BossBiMapper) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Duration(java.time.Duration) Path(java.nio.file.Path) Role(com.icodici.universa.contract.roles.Role) LogPrinter(net.sergeych.utils.LogPrinter) ListRole(com.icodici.universa.contract.roles.ListRole) com.icodici.universa.contract.services(com.icodici.universa.contract.services) PreparedStatement(java.sql.PreparedStatement) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) DbPool(com.icodici.db.DbPool) ZoneId(java.time.ZoneId) EncryptionError(com.icodici.crypto.EncryptionError) MatcherAssert(org.hamcrest.MatcherAssert) Crc32(com.icodici.crypto.digest.Crc32) PooledDb(com.icodici.db.PooledDb) Compound(com.icodici.universa.contract.helpers.Compound) EscrowHelper(com.icodici.universa.contract.helpers.EscrowHelper) Matchers.is(org.hamcrest.Matchers.is) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) ChronoField(java.time.temporal.ChronoField) NonNull(org.checkerframework.checker.nullness.qual.NonNull) java.util(java.util) com.icodici.universa.node(com.icodici.universa.node) net.sergeych.tools(net.sergeych.tools) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) PublicKey(com.icodici.crypto.PublicKey) com.icodici.universa.contract(com.icodici.universa.contract) com.icodici.universa.node2.network(com.icodici.universa.node2.network) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) PrivateKey(com.icodici.crypto.PrivateKey) Files(java.nio.file.Files) Semaphore(java.util.concurrent.Semaphore) KeyAddress(com.icodici.crypto.KeyAddress) Matchers(org.hamcrest.Matchers) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) com.icodici.universa(com.icodici.universa) TimeUnit(java.util.concurrent.TimeUnit) Db(com.icodici.db.Db) ChronoUnit(java.time.temporal.ChronoUnit) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) RoleLink(com.icodici.universa.contract.roles.RoleLink) Assert(org.junit.Assert) Boss(net.sergeych.boss.Boss) PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 23 with Network

use of com.google.api.ads.admanager.axis.v202205.Network in project universa by UniversaBlockchain.

the class MainTest method testPermanetMode.

@Test
public void testPermanetMode() throws Exception {
    // init network in permanet mode
    List<Main> mm = new ArrayList<>();
    for (int i = 0; i < 4; i++) mm.add(createMain("node" + (i + 1), "_permanet", false));
    Main main = mm.get(0);
    main.config.setIsFreeRegistrationsAllowedFromYaml(true);
    main.config.getKeysWhiteList().add(TestKeys.publicKey(20));
    Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
    assertTrue(main.config.isPermanetMode());
    for (int i = 1; i < 4; i++) assertTrue(mm.get(i).config.isPermanetMode());
    // try cancel permanet mode
    main.config.setPermanetMode(false);
    assertTrue(main.config.isPermanetMode());
    Set<PrivateKey> privateKeys = new HashSet<>(asList(TestKeys.privateKey(0)));
    Set<PublicKey> publicKeys = new HashSet<>();
    for (PrivateKey pk : privateKeys) {
        publicKeys.add(pk.getPublicKey());
    }
    Contract payment = InnerContractsService.createFreshU(100, publicKeys, true);
    payment.check();
    payment.traceErrors();
    ItemResult itemResult = client.register(payment.getPackedTransaction(), 5000);
    System.out.println("payment : " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    Thread.sleep(2000);
    // check keeping contract
    for (int i = 1; i < 4; i++) {
        byte[] keeping = mm.get(i).node.getLedger().getKeepingItem(payment.getId());
        assertNotNull(keeping);
        assertTrue(Arrays.equals(payment.getPackedTransaction(), keeping));
    }
    Contract baseContract = Contract.fromDslFile(ROOT_PATH + "DeLoreanOwnership.yml");
    PrivateKey manufacturePrivateKey = new PrivateKey(Do.read(ROOT_PATH + "_xer0yfe2nn1xthc.private.unikey"));
    baseContract.setExpiresAt(ZonedDateTime.now().plusSeconds(5));
    baseContract.addSignerKey(manufacturePrivateKey);
    baseContract.seal();
    baseContract.check();
    baseContract.traceErrors();
    itemResult = client.register(baseContract.getPackedTransaction(), 5000);
    System.out.println("contract : " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    Thread.sleep(2000);
    // check keeping contract
    for (int i = 1; i < 4; i++) {
        byte[] keeping = mm.get(i).node.getLedger().getKeepingItem(baseContract.getId());
        assertNotNull(keeping);
        assertTrue(Arrays.equals(baseContract.getPackedTransaction(), keeping));
    }
    Thread.sleep(8000);
    itemResult = client.getState(baseContract.getId());
    System.out.println("expired : " + itemResult);
    assertEquals(ItemState.UNDEFINED, itemResult.state);
    // check for expired contract
    for (int i = 1; i < 4; i++) {
        byte[] keeping = mm.get(i).node.getLedger().getKeepingItem(baseContract.getId());
        assertNotNull(keeping);
        assertTrue(Arrays.equals(baseContract.getPackedTransaction(), keeping));
    }
    main.config.setIsFreeRegistrationsAllowedFromYaml(false);
    Contract parcelContract = Contract.fromDslFile(ROOT_PATH + "LamborghiniOwnership.yml");
    parcelContract.setOwnerKeys(TestKeys.privateKey(1).getPublicKey());
    parcelContract.addSignerKey(manufacturePrivateKey);
    parcelContract.seal();
    parcelContract.check();
    parcelContract.traceErrors();
    Parcel parcel = createParcelWithFreshU(client, parcelContract, privateKeys);
    client.registerParcelWithState(parcel.pack(), 8000);
    itemResult = client.getState(parcel.getPayloadContract().getId());
    System.out.println("root : " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    Thread.sleep(2000);
    // check keeping contract
    for (int i = 1; i < 4; i++) {
        byte[] keeping = mm.get(i).node.getLedger().getKeepingItem(parcel.getPayloadContract().getId());
        assertNotNull(keeping);
        assertTrue(Arrays.equals(parcel.getPayloadContract().getPackedTransaction(), keeping));
    }
    // create revision
    Contract revisionContract = parcelContract.createRevision(manufacturePrivateKey);
    revisionContract.setOwnerKeys(TestKeys.privateKey(2).getPublicKey());
    revisionContract.addSignerKey(TestKeys.privateKey(1));
    revisionContract.seal();
    revisionContract.check();
    revisionContract.traceErrors();
    parcel = createParcelWithFreshU(client, revisionContract, privateKeys);
    client.registerParcelWithState(parcel.pack(), 8000);
    itemResult = client.getState(parcel.getPayloadContract().getId());
    System.out.println("revision : " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    itemResult = client.getState(parcelContract.getId());
    System.out.println("root : " + itemResult);
    assertEquals(ItemState.REVOKED, itemResult.state);
    Thread.sleep(2000);
    // check keeping contract
    for (int i = 1; i < 4; i++) {
        byte[] keeping_root = mm.get(i).node.getLedger().getKeepingItem(parcelContract.getId());
        byte[] keeping_revision = mm.get(i).node.getLedger().getKeepingItem(revisionContract.getId());
        assertNotNull(keeping_root);
        assertNotNull(keeping_revision);
        assertTrue(Arrays.equals(parcelContract.getPackedTransaction(), keeping_root));
        assertTrue(Arrays.equals(revisionContract.getPackedTransaction(), keeping_revision));
    }
    // revoke contract
    Contract revokeContract = ContractsService.createRevocation(revisionContract, manufacturePrivateKey);
    revokeContract.seal();
    revokeContract.check();
    revokeContract.traceErrors();
    parcel = createParcelWithFreshU(client, revokeContract, privateKeys);
    client.registerParcelWithState(parcel.pack(), 8000);
    itemResult = client.getState(parcel.getPayloadContract().getId());
    System.out.println("revocation : " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    itemResult = client.getState(parcelContract.getId());
    System.out.println("revision : " + itemResult);
    assertEquals(ItemState.REVOKED, itemResult.state);
    itemResult = client.getState(revisionContract.getId());
    System.out.println("root : " + itemResult);
    assertEquals(ItemState.REVOKED, itemResult.state);
    Thread.sleep(2000);
    // check keeping contract
    for (int i = 1; i < 4; i++) {
        byte[] keeping_root = mm.get(i).node.getLedger().getKeepingItem(parcelContract.getId());
        byte[] keeping_revision = mm.get(i).node.getLedger().getKeepingItem(revisionContract.getId());
        byte[] keeping_revoke = mm.get(i).node.getLedger().getKeepingItem(revokeContract.getId());
        assertNotNull(keeping_root);
        assertNotNull(keeping_revision);
        assertNotNull(keeping_revoke);
        assertTrue(Arrays.equals(parcelContract.getPackedTransaction(), keeping_root));
        assertTrue(Arrays.equals(revisionContract.getPackedTransaction(), keeping_revision));
        assertTrue(Arrays.equals(revokeContract.getPackedTransaction(), keeping_revoke));
    }
    HashSet<PrivateKey> own = new HashSet<>(Do.listOf(manufacturePrivateKey));
    // create revision
    Contract rootContract = ContractsService.createTokenContract(own, new HashSet<>(Do.listOf(manufacturePrivateKey.getPublicKey())), "10000");
    rootContract.seal();
    parcel = createParcelWithFreshU(client, rootContract, privateKeys);
    client.registerParcelWithState(parcel.pack(), 8000);
    itemResult = client.getState(parcel.getPayloadContract().getId());
    System.out.println("root : " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    List<Contract> splitres = ContractsService.createSplitJoin(Do.listOf(rootContract), Do.listOf("100", "200", "300", "400"), Do.listOf(TestKeys.publicKey(1).getShortAddress(), TestKeys.publicKey(2).getShortAddress(), TestKeys.publicKey(3).getShortAddress(), TestKeys.publicKey(4).getShortAddress()), own, "amount");
    parcel = createParcelWithFreshU(client, splitres.get(0), privateKeys);
    client.registerParcelWithState(parcel.pack(), 8000);
    itemResult = client.getState(parcel.getPayloadContract().getId());
    System.out.println("split : " + itemResult);
    assertEquals(ItemState.APPROVED, itemResult.state);
    List<HashId> ids = client.getChildren(rootContract.getId(), 5).getListOrThrow("ids");
    System.out.println("children : " + ids);
    List<HashId> ids2 = client.getChildren(rootContract.getId(), 3).getListOrThrow("ids");
    List<HashId> ids3 = client.getChildren(rootContract.getId(), 3, 3).getListOrThrow("ids");
    HashSet set1 = new HashSet(ids);
    HashSet set2 = new HashSet(ids2);
    set2.addAll(ids3);
    assertEquals(set1, set2);
    assertEquals(ids.size(), splitres.size());
    assertTrue(splitres.stream().allMatch(c -> ids.contains(c.getId())));
    mm.forEach(x -> x.shutdown());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) SecureLoanHelper(com.icodici.universa.contract.helpers.SecureLoanHelper) TimeoutException(java.util.concurrent.TimeoutException) BigDecimal(java.math.BigDecimal) com.icodici.universa.contract.permissions(com.icodici.universa.contract.permissions) java.net(java.net) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BossBiMapper(net.sergeych.biserializer.BossBiMapper) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Duration(java.time.Duration) Path(java.nio.file.Path) Role(com.icodici.universa.contract.roles.Role) LogPrinter(net.sergeych.utils.LogPrinter) ListRole(com.icodici.universa.contract.roles.ListRole) com.icodici.universa.contract.services(com.icodici.universa.contract.services) PreparedStatement(java.sql.PreparedStatement) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) DbPool(com.icodici.db.DbPool) ZoneId(java.time.ZoneId) EncryptionError(com.icodici.crypto.EncryptionError) MatcherAssert(org.hamcrest.MatcherAssert) Crc32(com.icodici.crypto.digest.Crc32) PooledDb(com.icodici.db.PooledDb) Compound(com.icodici.universa.contract.helpers.Compound) EscrowHelper(com.icodici.universa.contract.helpers.EscrowHelper) Matchers.is(org.hamcrest.Matchers.is) DateTimeFormatterBuilder(java.time.format.DateTimeFormatterBuilder) ChronoField(java.time.temporal.ChronoField) NonNull(org.checkerframework.checker.nullness.qual.NonNull) java.util(java.util) com.icodici.universa.node(com.icodici.universa.node) net.sergeych.tools(net.sergeych.tools) SimpleRole(com.icodici.universa.contract.roles.SimpleRole) PublicKey(com.icodici.crypto.PublicKey) com.icodici.universa.contract(com.icodici.universa.contract) com.icodici.universa.node2.network(com.icodici.universa.node2.network) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) PrivateKey(com.icodici.crypto.PrivateKey) Files(java.nio.file.Files) Semaphore(java.util.concurrent.Semaphore) KeyAddress(com.icodici.crypto.KeyAddress) Matchers(org.hamcrest.Matchers) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) com.icodici.universa(com.icodici.universa) TimeUnit(java.util.concurrent.TimeUnit) Db(com.icodici.db.Db) ChronoUnit(java.time.temporal.ChronoUnit) Ignore(org.junit.Ignore) Paths(java.nio.file.Paths) RoleLink(com.icodici.universa.contract.roles.RoleLink) Assert(org.junit.Assert) Boss(net.sergeych.boss.Boss) PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) Test(org.junit.Test)

Example 24 with Network

use of com.google.api.ads.admanager.axis.v202205.Network in project googleads-java-lib by googleads.

the class GetAllNetworks method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get all networks that you have access to with the current authentication
    // credentials.
    Network[] networks = networkService.getAllNetworks();
    int i = 0;
    for (Network network : networks) {
        System.out.printf("%d) Network with network code '%s' and display name '%s' was found.%n", i++, network.getNetworkCode(), network.getDisplayName());
    }
    System.out.printf("Number of networks found: %d%n", networks.length);
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) Network(com.google.api.ads.admanager.axis.v202202.Network)

Example 25 with Network

use of com.google.api.ads.admanager.axis.v202205.Network in project googleads-java-lib by googleads.

the class GetCurrentNetwork method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws RemoteException {
    // Get the NetworkService.
    NetworkServiceInterface networkService = adManagerServices.get(session, NetworkServiceInterface.class);
    // Get the current network.
    Network network = networkService.getCurrentNetwork();
    System.out.printf("Current network has network code '%s' and display name '%s'.%n", network.getNetworkCode(), network.getDisplayName());
}
Also used : NetworkServiceInterface(com.google.api.ads.admanager.axis.v202202.NetworkServiceInterface) Network(com.google.api.ads.admanager.axis.v202202.Network)

Aggregations

NetworkServiceInterface (com.google.api.ads.admanager.axis.v202205.NetworkServiceInterface)12 Network (com.google.api.ads.admanager.axis.v202205.Network)6 Random (java.util.Random)5 Network (com.google.api.ads.admanager.axis.v202111.Network)4 NetworkServiceInterface (com.google.api.ads.admanager.axis.v202111.NetworkServiceInterface)4 AdUnitTargeting (com.google.api.ads.admanager.axis.v202205.AdUnitTargeting)4 InventoryTargeting (com.google.api.ads.admanager.axis.v202205.InventoryTargeting)4 Size (com.google.api.ads.admanager.axis.v202205.Size)4 com.icodici.universa (com.icodici.universa)4 com.icodici.universa.contract (com.icodici.universa.contract)4 Role (com.icodici.universa.contract.roles.Role)4 RoleLink (com.icodici.universa.contract.roles.RoleLink)4 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)4 com.icodici.universa.node2.network (com.icodici.universa.node2.network)4 BigDecimal (java.math.BigDecimal)4 Instant (java.time.Instant)4 ZonedDateTime (java.time.ZonedDateTime)4 java.util (java.util)4 Arrays.asList (java.util.Arrays.asList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4