private void testIssueMultipleFullAssets()
      throws CantDefineContractPropertyException, CantIssueDigitalAssetsException {
    LOG.info("MAP_TEST_MULTIPLE_FULL_ASSETS");
    DigitalAsset digitalAsset = new DigitalAsset();
    digitalAsset.setPublicKey(new ECCKeyPair().getPublicKey());
    digitalAsset.setDescription("Descripcion de prueba");
    digitalAsset.setGenesisAddress(
        new CryptoAddress("n1zVgphtAoxgDMUzKV5ATeggwvUwnssb7m", CryptoCurrency.BITCOIN));
    digitalAsset.setGenesisAmount(1000);

    List<Resource> resources = new ArrayList<>();
    Resource resource = new Resource();
    resource.setId(UUID.randomUUID());
    resource.setName("Foto 1");
    resource.setFileName("imagen2.png");
    resource.setResourceType(ResourceType.IMAGE);
    resource.setResourceDensity(ResourceDensity.HDPI);
    resource.setResourceBinayData(
        new byte[] {0xa, 0x2, 0xf, (byte) 0xff, (byte) 0xff, (byte) 0xff});

    Resource resource2 = new Resource();
    resource2.setId(UUID.randomUUID());
    resource2.setName("Foto 1");
    resource2.setFileName("imagen2.png");
    resource2.setResourceType(ResourceType.IMAGE);
    resource2.setResourceDensity(ResourceDensity.HDPI);
    resource2.setResourceBinayData(
        new byte[] {0xa, 0x2, 0xf, (byte) 0xff, (byte) 0xff, (byte) 0xff});

    Resource resource3 = new Resource();
    resource3.setId(UUID.randomUUID());
    resource3.setName("Foto 1");
    resource3.setFileName("imagen2.png");
    resource3.setResourceType(ResourceType.IMAGE);
    resource3.setResourceDensity(ResourceDensity.HDPI);
    resource3.setResourceBinayData(
        new byte[] {0xa, 0x2, 0xf, (byte) 0xff, (byte) 0xff, (byte) 0xff});

    resources.add(resource);
    resources.add(resource2);
    resources.add(resource3);
    digitalAsset.setResources(resources);
    IdentityAssetIssuer identityAssetIssuer = new MockIdentityAssetIssuerForTest();
    digitalAsset.setName("Asset de prueba");
    digitalAsset.setIdentityAssetIssuer(identityAssetIssuer);
    DigitalAssetContract contract = new DigitalAssetContract();
    contract.setContractProperty(
        new ContractProperty(DigitalAssetContractPropertiesConstants.REDEEMABLE, Boolean.TRUE));
    digitalAsset.setContract(contract);

    System.out.println(digitalAsset.toString());
    this.assetIssuingTransactionManager.issueAssets(
        digitalAsset, 10, "TESTING PUBLICKEY", BlockchainNetworkType.REG_TEST);
    LOG.info("MAP_END_TEST_MULTIPLE_FULL_ASSETS");
  }
  private void testDigitalAssetMetadataVault()
      throws CantCreateDigitalAssetFileException, CantGetDigitalAssetFromLocalStorageException {
    Logger LOG = Logger.getGlobal();
    LOG.info("MAP_TEST_DAMVault");
    DigitalAsset digitalAsset = new DigitalAsset();
    digitalAsset.setGenesisAmount(100000);
    digitalAsset.setDescription("TestAsset");
    digitalAsset.setName("testName");
    digitalAsset.setPublicKey(new ECCKeyPair().getPublicKey());
    LOG.info("MAP_DigitalAsset:" + digitalAsset);
    List<Resource> resources = new ArrayList<>();
    digitalAsset.setResources(resources);

    digitalAsset.setIdentityAssetIssuer(null);
    DigitalAssetContract digitalAssetContract = new DigitalAssetContract();
    digitalAsset.setContract(digitalAssetContract);
    LOG.info("MAP_DigitalAsset2:" + digitalAsset);
    DigitalAssetMetadata dam = new DigitalAssetMetadata(digitalAsset);
    dam.setGenesisTransaction("testGenesisTX");
    this.digitalAssetIssuingVault.persistDigitalAssetMetadataInLocalStorage(dam, "testId");
    LOG.info(
        "DAM from vault:\n"
            + this.digitalAssetIssuingVault
                .getDigitalAssetMetadataFromLocalStorage("testGenesisTX")
                .toString());
  }
Esempio n. 3
0
 public static boolean isDigitalAssetComplete(DigitalAssetMetadata digitalAssetMetadata) {
   try {
     DigitalAsset digitalAsset = digitalAssetMetadata.getDigitalAsset();
     areObjectsSettled(digitalAsset);
     CryptoAddress genesisAddress = digitalAsset.getGenesisAddress();
     if (Validate.isObjectNull(genesisAddress)) {
       return false;
     }
     String digitalAssetHash = digitalAssetMetadata.getDigitalAssetHash();
     if (Validate.isValidString(digitalAssetHash)) {
       return false;
     }
     return true;
   } catch (ObjectNotSetException e) {
     return false;
   }
 }
 /**
  * This method implement a delivering test to asset issuer wallet, mocking an event raise and
  * transactions
  *
  * @throws CantDefineContractPropertyException
  * @throws CantCreateDigitalAssetFileException
  * @throws CantPersistDigitalAssetException
  * @throws CantSetObjectException
  * @throws CantExecuteQueryException
  * @throws UnexpectedResultReturnedFromDatabaseException
  * @throws CantPersistsGenesisTransactionException
  * @throws CantCheckAssetIssuingProgressException
  * @throws CantStartAgentException
  * @throws CantGetLoggedInDeviceUserException
  * @throws CantCreateFileException
  * @throws CantPersistFileException
  */
 private void testWalletDeliverAssetToAssetIssuerWallet()
     throws CantDefineContractPropertyException, CantCreateDigitalAssetFileException,
         CantPersistDigitalAssetException, CantSetObjectException, CantExecuteQueryException,
         UnexpectedResultReturnedFromDatabaseException, CantPersistsGenesisTransactionException,
         CantCheckAssetIssuingProgressException, CantStartAgentException,
         CantGetLoggedInDeviceUserException, CantCreateFileException, CantPersistFileException,
         CantPersistsTransactionUUIDException, CantPersistsGenesisAddressException {
   printSomething("Start deliver to Asset wallet test");
   String genesisTransaction = "d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43";
   MockDigitalAssetMetadataForTesting mockDigitalAssetMetadataForTesting =
       new MockDigitalAssetMetadataForTesting();
   DigitalAsset mockDigitalAssetForTesting = mockDigitalAssetMetadataForTesting.getDigitalAsset();
   String digitalAssetInnerXML = mockDigitalAssetForTesting.toString();
   //        PluginTextFile digitalAssetFile=this.pluginFileSystem.createTextFile(this.pluginId,
   // "digital-asset-swap/", genesisTransaction+".xml", FilePrivacy.PUBLIC,
   // FileLifeSpan.PERMANENT);
   //        digitalAssetFile.setContent(digitalAssetInnerXML);
   //        digitalAssetFile.persistToMedia();
   this.digitalAssetIssuingVault.setWalletPublicKey("walletPublicKeyTest");
   this.digitalAssetIssuingVault.persistDigitalAssetMetadataInLocalStorage(
       mockDigitalAssetMetadataForTesting, "testId");
   this.assetIssuingTransactionDao.persistDigitalAsset(
       mockDigitalAssetForTesting.getPublicKey(),
       "testLocalPath",
       1,
       BlockchainNetworkType.REG_TEST,
       "testWalletPublicKey");
   this.assetIssuingTransactionDao.persistDigitalAssetTransactionId(
       mockDigitalAssetForTesting.getPublicKey(), "testId");
   this.assetIssuingTransactionDao.persistDigitalAssetHash(
       "testId", mockDigitalAssetMetadataForTesting.getDigitalAssetHash());
   UUID mockUUId = UUID.randomUUID();
   this.assetIssuingTransactionDao.persistOutgoingIntraActorUUID("testId", mockUUId);
   this.assetIssuingTransactionDao.persistGenesisTransaction(
       mockUUId.toString(), genesisTransaction);
   this.assetIssuingTransactionDao.updateTransactionProtocolStatus(
       genesisTransaction, ProtocolStatus.TO_BE_NOTIFIED);
   this.assetIssuingTransactionDao.updateDigitalAssetTransactionStatus(
       "testId", TransactionStatus.CRYPTO_SENT);
   this.assetIssuingTransactionDao.updateDigitalAssetCryptoStatusByTransactionHash(
       mockDigitalAssetMetadataForTesting.getDigitalAssetHash(), CryptoStatus.PENDING_SUBMIT);
   testRaiseEvent();
   startMonitorAgent();
   printSomething("End Deliver test");
 }
  private void testIssueSingleAsset() throws CantIssueDigitalAssetsException {
    Logger LOG = Logger.getGlobal();
    LOG.info("MAP_TEST_SINGLE");
    DigitalAsset digitalAsset = new DigitalAsset();
    digitalAsset.setGenesisAmount(100000);
    digitalAsset.setDescription("TestAsset");
    digitalAsset.setName("testName");
    digitalAsset.setPublicKey(new ECCKeyPair().getPublicKey());
    LOG.info("MAP_DigitalAsset:" + digitalAsset);
    List<Resource> resources = new ArrayList<>();
    digitalAsset.setResources(resources);

    digitalAsset.setIdentityAssetIssuer(null);
    DigitalAssetContract digitalAssetContract = new DigitalAssetContract();
    digitalAsset.setContract(digitalAssetContract);
    LOG.info("MAP_DigitalAsset2:" + digitalAsset);

    this.issueAssets(
        digitalAsset, 1, new ECCKeyPair().getPublicKey(), BlockchainNetworkType.REG_TEST);
  }
Esempio n. 6
0
 /**
  * This method checks that every object in Digital asset is set.
  *
  * @throws ObjectNotSetException
  */
 public static void areObjectsSettled(DigitalAsset digitalAsset) throws ObjectNotSetException {
   if (digitalAsset.getContract() == null) {
     throw new ObjectNotSetException("Digital Asset Contract is not set");
   }
   if (digitalAsset.getResources() == null) {
     throw new ObjectNotSetException("Digital Asset Resources is not set");
   }
   if (digitalAsset.getDescription() == null) {
     throw new ObjectNotSetException("Digital Asset Description is not set");
   }
   if (digitalAsset.getName() == null) {
     throw new ObjectNotSetException("Digital Asset Name is not set");
   }
   if (digitalAsset.getPublicKey() == null) {
     throw new ObjectNotSetException("Digital Asset PublicKey is not set");
   }
   if (digitalAsset.getState() == null) {
     digitalAsset.setState(State.DRAFT);
   }
   if (digitalAsset.getIdentityAssetIssuer() == null) {
     throw new ObjectNotSetException("Digital Asset Identity is not set");
   }
 }
  @Before
  public void setUp() throws Exception {
    pluginId = UUID.randomUUID();

    assetIssuingPluginRoot = new AssetIssuingDigitalAssetTransactionPluginRoot();
    assetIssuingPluginRoot.setId(pluginId);
    assetIssuingPluginRoot.setErrorManager(errorManager);
    assetIssuingPluginRoot.setLogManager(logManager);
    assetIssuingPluginRoot.setEventManager(eventManager);
    assetIssuingPluginRoot.setPluginDatabaseSystem(pluginDatabaseSystem);
    assetIssuingPluginRoot.setPluginFileSystem(pluginFileSystem);
    assetIssuingPluginRoot.setAssetIssuerManager(assetIssuerWalletManager);
    assetIssuingPluginRoot.setActorAssetIssuerManager(actorAssetIssuerManager);
    assetIssuingPluginRoot.setCryptoVaultManager(cryptoVaultManager);
    assetIssuingPluginRoot.setBitcoinWalletManager(bitcoinWalletManager);
    assetIssuingPluginRoot.setAssetVaultManager(assetVaultManager);
    assetIssuingPluginRoot.setCryptoAddressBookManager(cryptoAddressBookManager);
    assetIssuingPluginRoot.setOutgoingIntraActorManager(outgoingIntraActorManager);
    assetIssuingPluginRoot.setDeviceUserManager(deviceUserManager);
    assetIssuingPluginRoot.setBitcoinNetworkManager(bitcoinNetworkManager);

    resources = new LinkedList<>();

    digitalAsset = new DigitalAsset();
    digitalAsset.setContract(digitalAssetContract);
    digitalAsset.setResources(resources);
    digitalAsset.setDescription(description);
    digitalAsset.setName(name);
    digitalAsset.setPublicKey(publicKey);
    digitalAsset.setState(state);
    digitalAsset.setIdentityAssetIssuer(identityAssetIssuer);

    records = new LinkedList<>();
    //        records.add(mockDatabaseTableRecord);

    setUpMockitoRules();
  }
 /** This method will deliver the DigitalAssetMetadata to ActorAssetUser */
 private void deliverDigitalAssetToRemoteDevice(
     DigitalAssetMetadata digitalAssetMetadata, ActorAssetUser actorAssetUser)
     throws CantDeliverDigitalAssetException {
   try {
     // First, I going to persist in database the basic information about digitalAssetMetadata
     System.out.println("ASSET DISTRIBUTION begins for " + actorAssetUser.getActorPublicKey());
     persistDigitalAsset(digitalAssetMetadata, actorAssetUser);
     System.out.println("ASSET DISTRIBUTION begins for persisted");
     // Now, I'll check is Hash wasn't modified
     // checkDigitalAssetMetadata(digitalAssetMetadata);
     DigitalAsset digitalAsset = digitalAssetMetadata.getDigitalAsset();
     System.out.println(
         "ASSET DISTRIBUTION Digital Asset genesis address: " + digitalAsset.getGenesisAddress());
     String genesisTransaction = digitalAssetMetadata.getGenesisTransaction();
     System.out.println("ASSET DISTRIBUTION Genesis transaction:" + genesisTransaction);
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CHECKING_AVAILABLE_BALANCE, genesisTransaction);
     if (!isAvailableBalanceInAssetVault(digitalAsset.getGenesisAmount(), genesisTransaction)) {
       System.out.println(
           "ASSET DISTRIBUTION The Available balance in asset vault is insufficient - genesisAmount:"
               + digitalAsset.getGenesisAmount());
       throw new CantDeliverDigitalAssetException(
           "The Available balance in asset vault is incorrect");
     }
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.AVAILABLE_BALANCE_CHECKED, genesisTransaction);
     DigitalAssetContract digitalAssetContract = digitalAsset.getContract();
     System.out.println("ASSET DISTRIBUTION Digital Asset contract: " + digitalAssetContract);
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CHECKING_CONTRACT, genesisTransaction);
     if (!isValidContract(digitalAssetContract)) {
       System.out.println("ASSET DISTRIBUTION The contract is not valid");
       throw new CantDeliverDigitalAssetException(
           "The DigitalAsset Contract is not valid, the expiration date has passed");
     }
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CONTRACT_CHECKED, genesisTransaction);
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.CHECKING_HASH, genesisTransaction);
     if (!isDigitalAssetHashValid(digitalAssetMetadata)) {
       System.out.println("ASSET DISTRIBUTION The DAM Hash is not valid");
       throw new CantDeliverDigitalAssetException("The DigitalAsset hash is not valid");
     }
     this.assetDistributionDao.updateDistributionStatusByGenesisTransaction(
         DistributionStatus.HASH_CHECKED, genesisTransaction);
     System.out.println(
         "ASSET DISTRIBUTION set debit in asset issuer wallet:" + genesisTransaction);
     digitalAssetDistributionVault.setDigitalAssetMetadataAssetIssuerWalletDebit(
         digitalAssetMetadata, this.cryptoTransaction, BalanceType.AVAILABLE);
     System.out.println("ASSET DISTRIBUTION Begins the deliver to an remote actor");
     deliverToRemoteActor(digitalAssetMetadata, actorAssetUser);
   } catch (CantPersistDigitalAssetException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot persist digital asset into database");
   } catch (CantCreateDigitalAssetFileException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "Cannot persist digital asset into local storage");
   } catch (CantGetCryptoTransactionException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "Cannot get the genesisTransaction from Asset Vault");
   } catch (CantExecuteQueryException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot execute a database operation");
   } catch (UnexpectedResultReturnedFromDatabaseException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Unexpected result in database");
   } catch (CantSendDigitalAssetMetadataException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "There is an error delivering the digital asset through the network layer");
   } catch (DAPException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Generic DAP Exception");
   } catch (CantGetTransactionsException exception) {
     throw new CantDeliverDigitalAssetException(
         exception,
         "Delivering digital assets",
         "Cannot get the genesis transaction from crypto network");
   } catch (CantLoadWalletException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot load Asset issuer wallet");
   } catch (CantRegisterDebitException exception) {
     throw new CantDeliverDigitalAssetException(
         exception, "Delivering digital assets", "Cannot register a debit in Asset Issuer Wallet");
   }
 }