wallet: conduct unit tests with both bip86 and bip32.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -892,7 +892,7 @@ static void cleanup_test_wallet(struct wallet *w, char *filename)
|
|||||||
tal_free(filename);
|
tal_free(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx)
|
static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
char *dsn, *filename;
|
char *dsn, *filename;
|
||||||
int fd = tmpdir_mkstemp(ctx, "ldb-XXXXXX", &filename);
|
int fd = tmpdir_mkstemp(ctx, "ldb-XXXXXX", &filename);
|
||||||
@@ -911,11 +911,16 @@ static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx
|
|||||||
w->ld = ld;
|
w->ld = ld;
|
||||||
ld->wallet = w;
|
ld->wallet = w;
|
||||||
|
|
||||||
ld->bip86_base = NULL;
|
|
||||||
ld->bip32_base = tal(ld, struct ext_key);
|
ld->bip32_base = tal(ld, struct ext_key);
|
||||||
CHECK(bip32_key_from_seed(badseed, sizeof(badseed),
|
CHECK(bip32_key_from_seed(badseed, sizeof(badseed),
|
||||||
BIP32_VER_TEST_PRIVATE, 0,
|
BIP32_VER_TEST_PRIVATE, 0,
|
||||||
ld->bip32_base) == WALLY_OK);
|
ld->bip32_base) == WALLY_OK);
|
||||||
|
if (bip86) {
|
||||||
|
ld->bip86_base = ld->bip32_base;
|
||||||
|
ld->bip32_base = NULL;
|
||||||
|
} else {
|
||||||
|
ld->bip86_base = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CHECK_MSG(w->db, "Failed opening the db");
|
CHECK_MSG(w->db, "Failed opening the db");
|
||||||
w->db->data_version = 0;
|
w->db->data_version = 0;
|
||||||
@@ -933,9 +938,9 @@ static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
|
static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx, bip86);
|
||||||
struct utxo u;
|
struct utxo u;
|
||||||
struct pubkey pk;
|
struct pubkey pk;
|
||||||
struct node_id id;
|
struct node_id id;
|
||||||
@@ -1145,10 +1150,10 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_shachain_crud(struct lightningd *ld, const tal_t *ctx)
|
static bool test_shachain_crud(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
struct wallet_shachain a, b;
|
struct wallet_shachain a, b;
|
||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx, bip86);
|
||||||
struct sha256 seed, hash;
|
struct sha256 seed, hash;
|
||||||
struct secret secret;
|
struct secret secret;
|
||||||
uint64_t index = UINT64_MAX >> (64 - SHACHAIN_BITS);
|
uint64_t index = UINT64_MAX >> (64 - SHACHAIN_BITS);
|
||||||
@@ -1344,9 +1349,9 @@ static struct channel *wallet_channel_load(struct wallet *w, const u64 dbid)
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx)
|
static bool test_channel_crud(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx, bip86);
|
||||||
struct channel c1, *c2 = tal(w, struct channel);
|
struct channel c1, *c2 = tal(w, struct channel);
|
||||||
struct wireaddr_internal addr;
|
struct wireaddr_internal addr;
|
||||||
struct peer *p;
|
struct peer *p;
|
||||||
@@ -1526,9 +1531,9 @@ static int count_inflights(struct wallet *w, u64 channel_dbid)
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
|
static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx, bip86);
|
||||||
struct channel *chan, *c2;
|
struct channel *chan, *c2;
|
||||||
struct channel_inflight *inflight;
|
struct channel_inflight *inflight;
|
||||||
struct bitcoin_outpoint outpoint;
|
struct bitcoin_outpoint outpoint;
|
||||||
@@ -1720,11 +1725,11 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_channel_config_crud(struct lightningd *ld, const tal_t *ctx)
|
static bool test_channel_config_crud(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
struct channel_config *cc1 = talz(ctx, struct channel_config),
|
struct channel_config *cc1 = talz(ctx, struct channel_config),
|
||||||
*cc2 = talz(ctx, struct channel_config);
|
*cc2 = talz(ctx, struct channel_config);
|
||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx, bip86);
|
||||||
CHECK(w);
|
CHECK(w);
|
||||||
|
|
||||||
cc1->dust_limit.satoshis = 1;
|
cc1->dust_limit.satoshis = 1;
|
||||||
@@ -1745,7 +1750,7 @@ static bool test_channel_config_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_htlc_crud(struct lightningd *ld, const tal_t *ctx)
|
static bool test_htlc_crud(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
struct db_stmt *stmt;
|
struct db_stmt *stmt;
|
||||||
struct htlc_in in, in2, *hin;
|
struct htlc_in in, in2, *hin;
|
||||||
@@ -1753,7 +1758,7 @@ static bool test_htlc_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
struct preimage payment_key;
|
struct preimage payment_key;
|
||||||
struct channel *chan = tal(ctx, struct channel);
|
struct channel *chan = tal(ctx, struct channel);
|
||||||
struct peer *peer = talz(ctx, struct peer);
|
struct peer *peer = talz(ctx, struct peer);
|
||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx, bip86);
|
||||||
struct htlc_in_map *htlcs_in = tal(ctx, struct htlc_in_map), *rem;
|
struct htlc_in_map *htlcs_in = tal(ctx, struct htlc_in_map), *rem;
|
||||||
struct htlc_out_map *htlcs_out = tal(ctx, struct htlc_out_map);
|
struct htlc_out_map *htlcs_out = tal(ctx, struct htlc_out_map);
|
||||||
struct onionreply *onionreply;
|
struct onionreply *onionreply;
|
||||||
@@ -1861,10 +1866,10 @@ static bool test_htlc_crud(struct lightningd *ld, const tal_t *ctx)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx)
|
static bool test_payment_crud(struct lightningd *ld, const tal_t *ctx, bool bip86)
|
||||||
{
|
{
|
||||||
struct wallet_payment *t, *t2;
|
struct wallet_payment *t, *t2;
|
||||||
struct wallet *w = create_test_wallet(ld, ctx);
|
struct wallet *w = create_test_wallet(ld, ctx, bip86);
|
||||||
struct sha256 payment_hash;
|
struct sha256 payment_hash;
|
||||||
struct node_id destination;
|
struct node_id destination;
|
||||||
|
|
||||||
@@ -1967,15 +1972,17 @@ int main(int argc, const char *argv[])
|
|||||||
|
|
||||||
/* We do a runtime test here, so we still check compile! */
|
/* We do a runtime test here, so we still check compile! */
|
||||||
if (HAVE_SQLITE3) {
|
if (HAVE_SQLITE3) {
|
||||||
ok &= test_shachain_crud(ld, tmpctx);
|
for (int bip86 = 0; bip86 < 2; bip86++) {
|
||||||
ok &= test_channel_crud(ld, tmpctx);
|
ok &= test_shachain_crud(ld, tmpctx, bip86);
|
||||||
ok &= test_channel_inflight_crud(ld, tmpctx);
|
ok &= test_channel_crud(ld, tmpctx, bip86);
|
||||||
ok &= test_channel_config_crud(ld, tmpctx);
|
ok &= test_channel_inflight_crud(ld, tmpctx, bip86);
|
||||||
ok &= test_channel_inflight_crud(ld, tmpctx);
|
ok &= test_channel_config_crud(ld, tmpctx, bip86);
|
||||||
ok &= test_wallet_outputs(ld, tmpctx);
|
ok &= test_channel_inflight_crud(ld, tmpctx, bip86);
|
||||||
ok &= test_htlc_crud(ld, tmpctx);
|
ok &= test_wallet_outputs(ld, tmpctx, bip86);
|
||||||
ok &= test_payment_crud(ld, tmpctx);
|
ok &= test_htlc_crud(ld, tmpctx, bip86);
|
||||||
ok &= test_wallet_payment_status_enum();
|
ok &= test_payment_crud(ld, tmpctx, bip86);
|
||||||
|
ok &= test_wallet_payment_status_enum();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do not clean up in the case of an error, we might want to debug the
|
/* Do not clean up in the case of an error, we might want to debug the
|
||||||
|
|||||||
Reference in New Issue
Block a user