Search in sources :

Example 1 with Purse

use of snowblossom.client.Purse in project snowblossom by snowblossomcoin.

the class PurseTest method testExtendXpub.

@Test
public void testExtendXpub() throws Exception {
    File empty_sub = new File(test_folder.newFolder(), "new");
    TreeMap<String, String> config_settings = new TreeMap<>();
    config_settings.put("key_mode", "seed");
    config_settings.put("watch_only", "true");
    ConfigMem config = new ConfigMem(config_settings);
    NetworkParams params = new NetworkParamsRegtest();
    String seed = SeedUtil.generateSeed(12);
    String xpub = SeedUtil.getSeedXpub(params, seed, "", 0);
    WalletDatabase db = WalletUtil.importXpub(params, xpub);
    db = WalletUtil.fillKeyPool(db, empty_sub, config, params);
    Assert.assertEquals(1, db.getXpubsCount());
    Assert.assertEquals(0, db.getUsedAddressesCount());
    Assert.assertEquals(20, db.getAddressesCount());
    Purse purse = new Purse(null, empty_sub, config, params);
    purse.maintainKeys(false);
    Assert.assertEquals(1, purse.getDB().getXpubsCount());
    Assert.assertEquals(0, purse.getDB().getUsedAddressesCount());
    Assert.assertEquals(20, purse.getDB().getAddressesCount());
    for (int i = 20; i < 100; i++) {
        Assert.assertTrue(purse.getDB().getAddressesCount() >= i);
        purse.getUnusedAddress(true, false);
        purse.maintainKeys(false);
        Assert.assertTrue(purse.getDB().getAddressesCount() - purse.getDB().getUsedAddressesCount() >= 20);
    }
}
Also used : Purse(snowblossom.client.Purse) TreeMap(java.util.TreeMap) File(java.io.File) ConfigMem(duckutil.ConfigMem) Test(org.junit.Test)

Example 2 with Purse

use of snowblossom.client.Purse in project snowblossom by snowblossomcoin.

the class PurseTest method testMarkRaceGen.

@Test
public void testMarkRaceGen() throws Exception {
    File empty_sub = new File(test_folder.newFolder(), "new");
    TreeMap<String, String> config_settings = new TreeMap<>();
    config_settings.put("key_pool_size", "100");
    config_settings.put("key_mode", "standard");
    ConfigMem config = new ConfigMem(config_settings);
    NetworkParams params = new NetworkParamsRegtest();
    WalletDatabase db = WalletUtil.makeNewDatabase(config, params);
    db = WalletUtil.fillKeyPool(db, empty_sub, config, params);
    Purse purse = new Purse(null, empty_sub, config, params);
    purse.maintainKeys(false);
    ThreadPoolExecutor exec = TaskMaster.getBasicExecutor(100, "test_fresh_race");
    TaskMaster<AddressSpecHash> tm = new TaskMaster<>(exec);
    for (int i = 0; i < 1000; i++) {
        tm.addTask(new Callable() {

            public AddressSpecHash call() throws Exception {
                return purse.getUnusedAddress(true, true);
            }
        });
    }
    ArrayList<AddressSpecHash> list = tm.getResults();
    Assert.assertEquals(1000, list.size());
    HashSet<AddressSpecHash> set = new HashSet<>();
    set.addAll(list);
    Assert.assertEquals(1000, set.size());
    Assert.assertEquals(1000, purse.getDB().getUsedAddressesCount());
    Assert.assertEquals(1100, purse.getDB().getAddressesCount());
    exec.shutdown();
}
Also used : Purse(snowblossom.client.Purse) TreeMap(java.util.TreeMap) ConfigMem(duckutil.ConfigMem) Callable(java.util.concurrent.Callable) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TaskMaster(duckutil.TaskMaster) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Purse

use of snowblossom.client.Purse in project snowblossom by snowblossomcoin.

the class PurseTest method testMarkRace.

@Test
public void testMarkRace() throws Exception {
    File empty_sub = new File(test_folder.newFolder(), "new");
    TreeMap<String, String> config_settings = new TreeMap<>();
    config_settings.put("key_pool_size", "100");
    ConfigMem config = new ConfigMem(config_settings);
    NetworkParams params = new NetworkParamsRegtest();
    WalletDatabase db = WalletUtil.makeNewDatabase(config, params);
    db = WalletUtil.fillKeyPool(db, empty_sub, config, params);
    Purse purse = new Purse(null, empty_sub, config, params);
    purse.maintainKeys(false);
    ThreadPoolExecutor exec = TaskMaster.getBasicExecutor(100, "test_fresh_race");
    TaskMaster<AddressSpecHash> tm = new TaskMaster<>(exec);
    for (int i = 0; i < 1000; i++) {
        tm.addTask(new Callable() {

            public AddressSpecHash call() throws Exception {
                return purse.getUnusedAddress(true, false);
            }
        });
    }
    ArrayList<AddressSpecHash> list = tm.getResults();
    Assert.assertEquals(1000, list.size());
    HashSet<AddressSpecHash> set = new HashSet<>();
    set.addAll(list);
    Assert.assertEquals(1000, set.size());
    Assert.assertEquals(1000, purse.getDB().getUsedAddressesCount());
    Assert.assertEquals(1000, purse.getDB().getAddressesCount());
    exec.shutdown();
}
Also used : Purse(snowblossom.client.Purse) TreeMap(java.util.TreeMap) ConfigMem(duckutil.ConfigMem) Callable(java.util.concurrent.Callable) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TaskMaster(duckutil.TaskMaster) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ConfigMem (duckutil.ConfigMem)3 File (java.io.File)3 TreeMap (java.util.TreeMap)3 Test (org.junit.Test)3 Purse (snowblossom.client.Purse)3 TaskMaster (duckutil.TaskMaster)2 HashSet (java.util.HashSet)2 Callable (java.util.concurrent.Callable)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2