if(extendedType != null) { try { scType = NSmartContract.SmartContractType.valueOf(extendedType); } catch (IllegalArgumentException e) {
assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.get("definition.extended_type")); assertEquals(100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue(), slotContract.getPrepaidKilobytesDays().doubleValue(), 0.01); System.out.println(">> " + slotContract.getPrepaidKilobytesDays().doubleValue() + " KD"); System.out.println(">> " + ((double)simpleContract.getPackedTransaction().length / 1024) + " Kb"); System.out.println(">> " + ((double)100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length) + " days"); for (Long envId : envs) { NImmutableEnvironment environment = networkNode.getLedger().getEnvironment(envId); double days = (double) 100 * networkNode.getConfig().getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length; double hours = days * 24; long seconds = (long) (days * 24 * 3600); for (Long envId : envs) { NImmutableEnvironment environment = node.getLedger().getEnvironment(envId); double days = (double) 100 * node.getConfig().getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length; double hours = days * 24; long seconds = (long) (days * 24 * 3600); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), refilledSlotContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), refilledSlotContract.get("definition.extended_type")); assertEquals((100 + 300) * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue(), refilledSlotContract.getPrepaidKilobytesDays().doubleValue(), 0.01); System.out.println(">> " + refilledSlotContract.getPrepaidKilobytesDays().doubleValue() + " KD"); System.out.println(">> " + ((double)simpleContract.getPackedTransaction().length / 1024) + " Kb"); System.out.println(">> " + ((double)simpleContract2.getPackedTransaction().length / 1024) + " Kb"); System.out.println(">> Summ: " + ((double)(simpleContract.getPackedTransaction().length + simpleContract2.getPackedTransaction().length) / 1024) + " Kb"); System.out.println(">> " + ((double)(100 + 300) * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / (simpleContract.getPackedTransaction().length + simpleContract2.getPackedTransaction().length)) + " days"); double days = (((double) (100 + 300) * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue()) - spentKDs) * 1024 / totalLength;
double callbackRate = testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = 200.0 * testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg.plusSeconds(seconds); days = 400.0 * testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); seconds = (long) (days * 24 * 3600); calculateExpires = timeReg.plusSeconds(seconds);
assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), newRevFollowerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), newRevFollowerContract.get("definition.extended_type")); assertEquals(400 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), newRevFollowerContract.getPrepaidOriginsDays().doubleValue(), 0.1); days = ((200 + 200) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue() - spentDays) / 2; seconds = (long) (days * 24 * 3600); calculateExpires = timeReg2.plusSeconds(seconds); double callbackRate = config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); days = callbackRate / newRevFollowerContract.getTrackingOrigins().size(); seconds = (long) (days * 24 * 3600); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), newRevFollowerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), newRevFollowerContract.get("definition.extended_type")); assertEquals(900 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), newRevFollowerContract.getPrepaidOriginsDays().doubleValue(), 0.1); days = ((200 + 200 + 500) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue() - spentDays) / 2; seconds = (long) (days * 24 * 3600);
assertTrue(followerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(250 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double callbackRate = config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = 250.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds);
assertTrue(followerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double callbackRate = config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds);
double callbackRate = testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = 200.0 * testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg.plusSeconds(seconds);
assertTrue(followerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); 1, 200, stepaPrivateKeys, false); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), newRevFollowerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), newRevFollowerContract.get("definition.extended_type")); assertEquals(400 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), newRevFollowerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double spentDays = (double) spentSeconds / (3600 * 24); days = ((200 + 200) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue() - spentDays) / 2; seconds = (long) (days * 24 * 3600); calculateExpires = timeReg2.plusSeconds(seconds);
assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.get("definition.extended_type")); assertEquals(100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue(), slotContract.getPrepaidKilobytesDays().doubleValue(), 0.01); double days = (double) 100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length; long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), refilledSlotContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), refilledSlotContract.get("definition.extended_type")); assertEquals((100 + 300) * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue(), refilledSlotContract.getPrepaidKilobytesDays().doubleValue(), 0.01); days = ((double) (100 + 300) * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() - spentKDs) * 1024 / simpleContract.getPackedTransaction().length; seconds = (long) (days * 24 * 3600); calculateExpires = timeReg2.plusSeconds(seconds); System.out.println(foundCss.expiresAt()); assertAlmostSame(calculateExpires, foundCss.expiresAt(), (long) (5 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue())); System.out.println(foundStorage.expiresAt()); assertAlmostSame(calculateExpires, foundStorage.expiresAt(), (long) (5 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue())); System.out.println(foundCss.expiresAt()); assertAlmostSame(calculateExpires, foundCss.expiresAt(), (long) (5 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue())); System.out.println(foundStorage.expiresAt());
assertTrue(followerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double callbackRate = config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds);
double callbackRate = testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = 200.0 * testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg.plusSeconds(seconds); days = 400.0 * testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); seconds = (long) (days * 24 * 3600); calculateExpires = timeReg.plusSeconds(seconds);
double callbackRate = testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = 200.0 * testSpace.node.config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg.plusSeconds(seconds);
assertTrue(followerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), refilledFollowerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), refilledFollowerContract.get("definition.extended_type")); assertEquals((200 + 300) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), refilledFollowerContract.getPrepaidOriginsDays().doubleValue(), 0.01); days = (200 + 300) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue() - spentDays; seconds = (long) (days * 24 * 3600); calculateExpires = timeReg2.plusSeconds(seconds); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), refilledFollowerContract2.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), refilledFollowerContract2.get("definition.extended_type")); assertEquals((200 + 300 + 300) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), refilledFollowerContract2.getPrepaidOriginsDays().doubleValue(), 0.01); days = (200 + 300 + 300) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue() - spentDays; seconds = (long) (days * 24 * 3600); calculateExpires = timeReg3.plusSeconds(seconds);
assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.get("definition.extended_type")); assertEquals(100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue(), slotContract.getPrepaidKilobytesDays().doubleValue(), 0.01); System.out.println(">> " + slotContract.getPrepaidKilobytesDays().doubleValue() + " KD"); System.out.println(">> " + ((double) simpleContract.getPackedTransaction().length / 1024) + " Kb"); System.out.println(">> " + ((double) 100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length) + " days"); for(Long envId : envs) { NImmutableEnvironment environment = networkNode.getLedger().getEnvironment(envId); double days = (double) 100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length; double hours = days * 24; long seconds = (long) (days * 24 * 3600); for(Long envId : envs) { NImmutableEnvironment environment = node.getLedger().getEnvironment(envId); double days = (double) 100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length; double hours = days * 24; long seconds = (long) (days * 24 * 3600); double days2 = ((double) 100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() - spentKDs) * 1024 / totalLength2; double hours2 = days2 * 24; long seconds2 = (long) (days2 * 24 * 3600); System.out.println("found " + foundCss.expiresAt()); assertAlmostSame(calculateExpires, foundCss.expiresAt(), (long) (5 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue())); System.out.println("found " + foundStorage.expiresAt()); assertAlmostSame(calculateExpires, foundStorage.expiresAt(),
assertTrue(followerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); 1, 200, stepaPrivateKeys, false); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract2.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract2.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract2.getPrepaidOriginsDays().doubleValue(), 0.1); days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires2 = timeReg2.plusSeconds(seconds);
assertTrue(followerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), followerContract.get("definition.extended_type")); assertEquals(200 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), followerContract.getPrepaidOriginsDays().doubleValue(), 0.1); double days = 200.0 * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); assertTrue(refilledFollowerContract.isOk()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), refilledFollowerContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.FOLLOWER1.name(), refilledFollowerContract.get("definition.extended_type")); assertEquals((200 + 300) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue(), refilledFollowerContract.getPrepaidOriginsDays().doubleValue(), 0.01); double spentDays = (double) spentSeconds / (3600 * 24); days = (200 + 300) * config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name()).doubleValue() - spentDays; seconds = (long) (days * 24 * 3600); calculateExpires = timeReg2.plusSeconds(seconds);
assertTrue(slotContract.isOk()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract.get("definition.extended_type")); assertEquals(100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue(), slotContract.getPrepaidKilobytesDays().doubleValue(), 0.01); double days = (double) 100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length; long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); assertTrue(slotContract2.isOk()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract2.getDefinition().getExtendedType()); assertEquals(NSmartContract.SmartContractType.SLOT1.name(), slotContract2.get("definition.extended_type")); assertEquals(100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue(), slotContract2.getPrepaidKilobytesDays().doubleValue(), 0.01); days = (double) 100 * config.getServiceRate(NSmartContract.SmartContractType.SLOT1.name()).doubleValue() * 1024 / simpleContract.getPackedTransaction().length; seconds = (long) (days * 24 * 3600); calculateExpires = timeReg2.plusSeconds(seconds);
double callbackRate = config.getServiceRate(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").doubleValue(); double days = callbackRate / origins; long seconds = (long) (days * 24 * 3600);
assertEquals(1470 * config.getServiceRate(NSmartContract.SmartContractType.UNS1.name()).doubleValue(), uns.getPrepaidNamesDays().doubleValue(), 0.01); double days = (double) 1470 * config.getServiceRate(NSmartContract.SmartContractType.UNS1.name()).doubleValue() / uns.getUnsName(reducedName).getRecordsCount(); long seconds = (long) (days * 24 * 3600); ZonedDateTime calculateExpires = timeReg1.plusSeconds(seconds); assertEquals(2470 * config.getServiceRate(NSmartContract.SmartContractType.UNS1.name()).doubleValue(), refilledUnsContract.getPrepaidNamesDays().doubleValue(), 0.01); double spentNDs = (double) spentSeconds / (3600 * 24); days = (double) (2470 - spentNDs) * config.getServiceRate(NSmartContract.SmartContractType.UNS1.name()).doubleValue() / refilledUnsContract.getUnsName(reducedName).getRecordsCount(); seconds = (long) (days * 24 * 3600); calculateExpires = timeReg2.plusSeconds(seconds);