public Client getClient(int i) throws IOException { Client c = clients.get(i); if (c == null) { NodeRecord r = nodes.get(i); c = new Client(r.url, clientPrivateKey, r.key, null); clients.set(i, c); } return c; }
@Override public ItemResult getItemState(NodeInfo nodeInfo, HashId id) throws IOException { Client client; synchronized (cachedClients) { client = cachedClients.get(nodeInfo); if( client == null ) { client = new Client(myKey, nodeInfo, null); cachedClients.put(nodeInfo, client); } } return client.getState(id); }
private Client createWhiteClient() { try { int nodeNumber = ThreadLocalRandom.current().nextInt(1, 11); String nodeUrl = "http://node-" + nodeNumber + "-pro.universa.io:8080"; PrivateKey clientKey = TestKeys.privateKey(nodeNumber-1); return new Client(nodeUrl, clientKey, null, false); } catch (Exception e) { System.out.println("createWhiteClient exception: " + e.toString()); return null; } }
public ClientNetwork(String nodeUrl, PrivateKey privateKey, BasicHttpClientSession session) throws IOException { client = new Client(nodeUrl, privateKey, session); if (client == null) throw new IOException("failed to connect to to the universa network"); reporter.verbose("Read Universa network configuration: " + client.size() + " nodes"); reporter.message("Network version: " + client.getVersion()); }
private static void createNodeClient() throws Exception { // List<Main> mm = new ArrayList<>(); // for (int i = 0; i < 4; i++) // mm.add(createMain("node" + (i + 1), false)); // // Thread.sleep(2000); clients = new ArrayList<>(); for (int i = 0; i < 10; ++i) { int n = i+1; String nodeUrl = "http://node-"+n+"-pro.universa.io:8080"; PrivateKey clientKey = TestKeys.privateKey(i); Client client = new Client(nodeUrl, clientKey, null, false); clients.add(client); } nodeClient = clients.get(0); Thread.sleep(100); }
public ClientNetwork(String nodeUrl, BasicHttpClientSession session, boolean delayedStart) throws IOException { client = new Client(nodeUrl, CLIMain.getPrivateKey(), session, delayedStart); if (client == null) throw new IOException("failed to connect to to the universa network"); reporter.verbose("Read Universa network configuration: " + client.size() + " nodes"); reporter.message("Network version: " + client.getVersion()); }
private TestSpace prepareTestSpace(PrivateKey key) throws Exception { TestSpace testSpace = new TestSpace(); testSpace.nodes = new ArrayList<>(); for (int i = 0; i < 4; i++) testSpace.nodes.add(createMain("node" + (i + 1), false)); testSpace.node = testSpace.nodes.get(0); assertEquals("http://localhost:8080", testSpace.node.myInfo.internalUrlString()); assertEquals("http://localhost:8080", testSpace.node.myInfo.publicUrlString()); testSpace.myKey = key; testSpace.client = new Client(testSpace.myKey, testSpace.node.myInfo, null); testSpace.clients = new ArrayList(); for (int i = 0; i < 4; i++) testSpace.clients.add(new Client(testSpace.myKey, testSpace.nodes.get(i).myInfo, null)); return testSpace; }
public ClientNetwork(BasicHttpClientSession session, boolean delayedStart) throws IOException { for (int i = 1; i < 10; i++) { try { client = new Client("http://node-" + Do.randomIntInRange(1, 10) + "-com.universa.io:8080", CLIMain.getPrivateKey(), session, delayedStart); break; } catch (IOException e) { reporter.warning("failed to read network from node " + i); } } if (client == null) throw new IOException("failed to connect to to the universa network"); reporter.verbose("Read Universa network configuration: " + client.size() + " nodes"); reporter.message("Network version: " + client.getVersion()); }
private TestSpace prepareTestSpace(PrivateKey key) throws Exception { TestSpace testSpace = new TestSpace(); testSpace.nodes = new ArrayList<>(); for (int i = 0; i < 4; i++) testSpace.nodes.add(createMain("node" + (i + 1), "", false)); testSpace.node = testSpace.nodes.get(0); assertEquals("http://localhost:8080", testSpace.node.myInfo.internalUrlString()); assertEquals("http://localhost:8080", testSpace.node.myInfo.publicUrlString()); testSpace.myKey = key; testSpace.client = new Client(testSpace.myKey, testSpace.node.myInfo, null); testSpace.clients = new ArrayList(); for (int i = 0; i < 4; i++) testSpace.clients.add(new Client(testSpace.myKey, testSpace.nodes.get(i).myInfo, null)); for (Main m : testSpace.nodes) { while (m.node.isSanitating()) Thread.sleep(100); } return testSpace; }
@Test public void freeRegistrationsAllowedFromCoreVersion() 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); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null); Contract contract = new Contract(TestKeys.privateKey(0)); contract.seal(); ItemState expectedState = ItemState.UNDEFINED; if (Core.VERSION.contains("private")) expectedState = ItemState.APPROVED; System.out.println("Core.VERSION: " + Core.VERSION); System.out.println("expectedState: " + expectedState); ItemResult itemResult = client.register(contract.getPackedTransaction(), 5000); System.out.println("itemResult: " + itemResult); assertEquals(expectedState, itemResult.state); mm.forEach(x -> x.shutdown()); }
@Test public void freeRegistrationsAllowedFromConfigOrVersion() 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); Contract contract = new Contract(TestKeys.privateKey(0)); contract.seal(); ItemState expectedState = ItemState.APPROVED; System.out.println("expectedState: " + expectedState); ItemResult itemResult = client.register(contract.getPackedTransaction(), 5000); System.out.println("itemResult: " + itemResult); assertEquals(expectedState, itemResult.state); main.config.setIsFreeRegistrationsAllowedFromYaml(false); contract = new Contract(TestKeys.privateKey(0)); contract.seal(); expectedState = ItemState.UNDEFINED; if (Core.VERSION.contains("private")) expectedState = ItemState.APPROVED; System.out.println("Core.VERSION: " + Core.VERSION); System.out.println("expectedState: " + expectedState); itemResult = client.register(contract.getPackedTransaction(), 5000); System.out.println("itemResult: " + itemResult); assertEquals(expectedState, itemResult.state); mm.forEach(x -> x.shutdown()); }
@Test public void paymentTest1() 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); Contract simpleContract = new Contract(TestKeys.privateKey(1)); simpleContract.seal(); Contract stepaU = InnerContractsService.createFreshU(100000000, new HashSet<>(Arrays.asList(TestKeys.publicKey(1)))); ItemResult itemResult = client.register(stepaU.getPackedTransaction(), 5000); System.out.println("stepaU itemResult: " + itemResult); assertEquals(ItemState.APPROVED, itemResult.state); main.config.setIsFreeRegistrationsAllowedFromYaml(false); Parcel parcel = ContractsService.createParcel(simpleContract, stepaU, 1, new HashSet<>(Arrays.asList(TestKeys.privateKey(1))), false); client.registerParcelWithState(parcel.pack(), 5000); assertEquals(ItemState.APPROVED, client.getState(simpleContract.getId()).state); mm.forEach(x -> x.shutdown()); } protected static final String ROOT_PATH = "./src/test_contracts/";
@Test public void checkWhiteListKey() throws Exception { List<Main> mm = new ArrayList<>(); for (int i = 0; i < 3; i++) { mm.add(createMain("node" + (i + 1), false)); } Main main = mm.get(0); PrivateKey myKey = TestKeys.privateKey(3); Client client = null; try { client = new Client(myKey, main.myInfo, null); } catch (Exception e) { System.out.println("prepareClient exception: " + e.toString()); } Contract testContract = new Contract(myKey); for (int i = 0; i < 10; i++) { Contract nc = new Contract(myKey); nc.seal(); testContract.addNewItems(nc); } testContract.seal(); assertTrue(testContract.isOk()); Parcel parcel = createParcelWithFreshU(client, testContract,Do.listOf(myKey)); ItemResult itemResult = client.registerParcelWithState(parcel.pack(), 15000); System.out.println(">> state: " + itemResult); assertEquals (ItemState.APPROVED, itemResult.state); mm.forEach(x -> x.shutdown()); }
@Test public void testRevocationContractsApi() 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> issuerPrivateKeys = new HashSet<>(Arrays.asList(TestKeys.privateKey(1))); Set<PublicKey> ownerPublicKeys = new HashSet<>(Arrays.asList(TestKeys.publicKey(2))); Contract sourceContract = ContractsService.createShareContract(issuerPrivateKeys, ownerPublicKeys, new BigDecimal("100")); sourceContract.check(); sourceContract.traceErrors(); ItemResult itemResult = client.register(sourceContract.getPackedTransaction(), 5000); System.out.println("sourceContract : " + itemResult); assertEquals(ItemState.APPROVED, client.getState(sourceContract.getId()).state); Contract revokeContract = ContractsService.createRevocation(sourceContract, TestKeys.privateKey(1)); revokeContract.check(); revokeContract.traceErrors(); itemResult = client.register(revokeContract.getPackedTransaction(), 5000); System.out.println("revokeContract : " + itemResult); assertEquals(ItemState.APPROVED, client.getState(revokeContract.getId()).state); assertEquals(ItemState.REVOKED, client.getState(sourceContract.getId()).state); mm.forEach(x -> x.shutdown()); }
Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
main.config.setIsFreeRegistrationsAllowedFromYaml(true); main.config.getKeysWhiteList().add(TestKeys.publicKey(20)); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);
Main main = mm.get(0); main.config.setIsFreeRegistrationsAllowedFromYaml(true); Client client = new Client(TestKeys.privateKey(20), main.myInfo, null);