bit.changepurse.wdk.bip.TestBip39JP.java Source code

Java tutorial

Introduction

Here is the source code for bit.changepurse.wdk.bip.TestBip39JP.java

Source

/*
 * This file is part of ChangePurse.
 *
 * Copyright (c) 2014 Germn Fuentes Capella
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package bit.changepurse.wdk.bip;

import static bit.changepurse.wdk.util.CheckedExceptionMethods.newURI;
import static bit.changepurse.wdk.util.CheckedExceptionMethods.readTextFile;

import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(value = Parameterized.class)
public class TestBip39JP extends TestBip39 {
    private static final String TEST_VECTORS = "bip39_jp_test_vectors.json";

    public TestBip39JP(String anInitialSeed, String aMnemonic, String anExpectedSeed, String passphrase,
            Bip39Dict aDict) {
        super(anInitialSeed, aMnemonic, anExpectedSeed, passphrase, aDict);
    }

    public static String readTestVectors() {
        URL resource = TestBip39JP.class.getResource(TEST_VECTORS);
        Path path = Paths.get(newURI(resource));
        return readTextFile(path);
    }

    @Parameters
    public static List<Object[]> data() {
        JSONArray json = new JSONArray(readTestVectors());
        List<Object[]> tests = new ArrayList<Object[]>();
        for (int i = 0; i < json.length(); i++) {
            JSONObject test = json.getJSONObject(i);
            tests.add(new Object[] { test.getString("entropy"), test.getString("phrase"), test.getString("seed"),
                    test.getString("salt"), Bip39Dict.JP });
        }
        return tests;
    }

}