
package org.coinspark.wallet;

import com.google.bitcoin.core.PeerGroup;
import org.coinspark.core.CSUtils;
import org.coinspark.protocol.CoinSparkAssetRef;
import org.coinspark.protocol.CoinSparkTransferList;

public class CSTests {
    
    private PeerGroup peerGroup;
    private String filePrefix;
    private CSAssetDatabase assetDB;
    private CSBalanceDatabase balanceDB;
    
    public CSTests(PeerGroup pg,String FilePrefix)
    {
        peerGroup=pg;
        filePrefix=FilePrefix;
        assetDB=new CSAssetDatabase(FilePrefix,null);
        balanceDB=new CSBalanceDatabase(FilePrefix, assetDB,null);
    }
    
    public void test()
    {
        test01();
    }
    
    private void test01()
    {        
        CoinSparkTransferList a=new CoinSparkTransferList();
                
        System.out.println("Test01 started");
        
        CoinSparkAssetRef assetRef=new CoinSparkAssetRef();
        assetRef.setBlockNum(208441);
        assetRef.setTxOffset(190);
        assetRef.setTxIDPrefix(CSUtils.hex2Byte("e0a8"));
        
        CSAsset asset=new CSAsset(assetRef, CSAsset.CSAssetSource.MANUAL);
        CSAsset found;
        
        found=assetDB.findAsset(asset);
        
        if(found != null)
        {
            System.out.println("Asset with reference " + asset.getAssetReference().toString() + " found with ID " + found.getAssetID());                    
        }
        else
        {
            found=assetDB.insertAsset(asset);            
            if(found != null)
            {
                System.out.println("Asset with reference " + asset.getAssetReference().toString() + " inserted with ID " + found.getAssetID());                    
            }
            else
            {
                System.out.println("Asset with reference " + asset.getAssetReference().toString() + " not inserted");                    
            }
        }

        if(found != null)
        {
            if(found.validate(assetDB.getDirName(), peerGroup,false))
            {
                assetDB.updateAsset(found);
            }
        }        
        
        System.out.println("Test01 completed");        
    }    
    
}
