|
|
@ -113,6 +113,18 @@ static bool test_shachain_crud(void) |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
static bool bitcoin_tx_eq(const struct bitcoin_tx *tx1, |
|
|
|
const struct bitcoin_tx *tx2) |
|
|
|
{ |
|
|
|
u8 *lin1, *lin2; |
|
|
|
bool eq; |
|
|
|
lin1 = linearize_tx(NULL, tx1); |
|
|
|
lin2 = linearize_tx(lin1, tx2); |
|
|
|
eq = memeq(lin1, tal_len(lin1), lin2, tal_len(lin2)); |
|
|
|
tal_free(lin1); |
|
|
|
return eq; |
|
|
|
} |
|
|
|
|
|
|
|
static bool channelseq(struct wallet_channel *c1, struct wallet_channel *c2) |
|
|
|
{ |
|
|
|
struct peer *p1 = c1->peer, *p2 = c2->peer; |
|
|
@ -154,6 +166,16 @@ static bool channelseq(struct wallet_channel *c1, struct wallet_channel *c2) |
|
|
|
CHECK(lc1->id == lc2->id); |
|
|
|
} |
|
|
|
|
|
|
|
CHECK((p1->last_tx != NULL) == (p2->last_tx != NULL)); |
|
|
|
if(p1->last_tx) { |
|
|
|
CHECK(bitcoin_tx_eq(p1->last_tx, p2->last_tx)); |
|
|
|
} |
|
|
|
CHECK((p1->last_sig != NULL) == (p2->last_sig != NULL)); |
|
|
|
if(p1->last_sig) { |
|
|
|
CHECK(memeq(p1->last_sig, sizeof(*p1->last_sig), |
|
|
|
p2->last_sig, sizeof(*p2->last_sig))); |
|
|
|
} |
|
|
|
|
|
|
|
CHECK((p1->closing_sig_received != NULL) == (p2->closing_sig_received != NULL)); |
|
|
|
if(p1->closing_sig_received) { |
|
|
|
CHECK(memeq(p1->closing_sig_received, |
|
|
@ -192,6 +214,7 @@ static bool test_channel_crud(const tal_t *ctx) |
|
|
|
p.id = pk; |
|
|
|
p.unique_id = 42; |
|
|
|
p.our_msatoshi = NULL; |
|
|
|
p.last_tx = NULL; |
|
|
|
memset(&ci.their_config, 0, sizeof(struct channel_config)); |
|
|
|
ci.remote_fundingkey = pk; |
|
|
|
ci.theirbase.revocation = pk; |
|
|
@ -200,7 +223,7 @@ static bool test_channel_crud(const tal_t *ctx) |
|
|
|
ci.remote_per_commit = pk; |
|
|
|
ci.old_remote_per_commit = pk; |
|
|
|
|
|
|
|
/* Variant 1: insert with null for scid, funding_tx_id, and channel_info */ |
|
|
|
/* Variant 1: insert with null for scid, funding_tx_id, channel_info, last_tx */ |
|
|
|
CHECK_MSG(wallet_channel_save(w, &c1), tal_fmt(w, "Insert into DB: %s", w->db->err)); |
|
|
|
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB: %s", w->db->err)); |
|
|
|
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v1)"); |
|
|
@ -245,12 +268,19 @@ static bool test_channel_crud(const tal_t *ctx) |
|
|
|
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB: %s", w->db->err)); |
|
|
|
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v6)"); |
|
|
|
|
|
|
|
/* Variant 7: update with closing_sig */ |
|
|
|
p.closing_sig_received = sig; |
|
|
|
/* Variant 7: update with last_tx (taken from BOLT #3) */ |
|
|
|
p.last_tx = bitcoin_tx_from_hex(w, "02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220", strlen("02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a488489000000000038b02b8003a00f0000000000002200208c48d15160397c9731df9bc3b236656efb6665fbfe92b4a6878e88a499f741c4c0c62d0000000000160014ccf1af2f2aabee14bb40fa3851ab2301de843110ae8f6a00000000002200204adb4e2f00643db396dd120d4e7dc17625f5f2c11a40d857accc862d6b7dd80e040047304402206a2679efa3c7aaffd2a447fd0df7aba8792858b589750f6a1203f9259173198a022008d52a0e77a99ab533c36206cb15ad7aeb2aa72b93d4b571e728cb5ec2f6fe260147304402206d6cb93969d39177a09d5d45b583f34966195b77c7e585cf47ac5cce0c90cefb022031d71ae4e33a4e80df7f981d696fbdee517337806a3c7138b7491e2cbb077a0e01475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae3e195220")); |
|
|
|
p.last_sig = sig; |
|
|
|
CHECK_MSG(wallet_channel_save(w, &c1), tal_fmt(w, "Insert into DB: %s", w->db->err)); |
|
|
|
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB: %s", w->db->err)); |
|
|
|
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v7)"); |
|
|
|
|
|
|
|
/* Variant 8: update with closing_sig */ |
|
|
|
p.closing_sig_received = sig; |
|
|
|
CHECK_MSG(wallet_channel_save(w, &c1), tal_fmt(w, "Insert into DB: %s", w->db->err)); |
|
|
|
CHECK_MSG(wallet_channel_load(w, c1.id, c2), tal_fmt(w, "Load from DB: %s", w->db->err)); |
|
|
|
CHECK_MSG(channelseq(&c1, c2), "Compare loaded with saved (v8)"); |
|
|
|
|
|
|
|
tal_free(w); |
|
|
|
return true; |
|
|
|
} |
|
|
|