Commit 2cf7b330 authored by Éloïs's avatar Éloïs
Browse files

Merge branch 'test_gva_revert_block' into 'dev'

[tests] gva-indexer: revert_block

See merge request nodes/typescript/duniter!1361
parents 7ef824c7 1234e1e0
......@@ -378,6 +378,131 @@ mod tests {
]
);
Ok(())
}
#[test]
fn test_gva_revert_block() -> anyhow::Result<()> {
let gva_db = GvaV1Db::<Mem>::open(MemConf::default())?;
let s1 = WalletScriptV10::single_sig(PublicKey::from_base58(
"D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx",
)?);
let s2 = WalletScriptV10::single_sig(PublicKey::from_base58(
"4fHMTFBMo5sTQEc5p1CNWz28S4mnnqdUBmECq1zt4n2m",
)?);
let b0 = DubpBlockV10::from_string_object(&DubpBlockV10Stringified {
version: 10,
median_time: 5_243,
dividend: Some(1000),
joiners: vec!["D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx:FFeyrvYio9uYwY5aMcDGswZPNjGLrl8THn9l3EPKSNySD3SDSHjCljSfFEwb87sroyzJQoVzPwER0sW/cbZMDg==:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855:elois".to_owned()],
inner_hash: Some("0000000A65A12DB95B3153BCD05DB4D5C30CC7F0B1292D9FFBC3DE67F72F6040".to_owned()),
signature: "7B0hvcfajE2G8nBLp0vLVaQcQdQIyli21Gu8F2l+nimKHRe+fUNi+MWd1e/u29BYZa+RZ1yxhbHIbFzytg7fAA==".to_owned(),
hash: Some("0000000000000000000000000000000000000000000000000000000000000000".to_owned()),
..Default::default()
})?;
apply_block(&b0, &gva_db)?;
let b1 = DubpBlockV10::from_string_object(&DubpBlockV10Stringified {
number: 1,
version: 10,
median_time: 5_245,
transactions: vec![TransactionDocumentV10Stringified {
currency: "test".to_owned(),
blockstamp: "0-0000000000000000000000000000000000000000000000000000000000000000".to_owned(),
locktime: 0,
issuers: vec!["D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx".to_owned()],
inputs: vec!["1000:0:D:D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx:0".to_owned()],
unlocks: vec![],
outputs: vec![
"600:0:SIG(4fHMTFBMo5sTQEc5p1CNWz28S4mnnqdUBmECq1zt4n2m)".to_owned(),
"400:0:SIG(D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx)".to_owned(),
],
comment: "".to_owned(),
signatures: vec![],
hash: Some("0000000000000000000000000000000000000000000000000000000000000000".to_owned()),
}],
inner_hash: Some("0000000A65A12DB95B3153BCD05DB4D5C30CC7F0B1292D9FFBC3DE67F72F6040".to_owned()),
signature: "7B0hvcfajE2G8nBLp0vLVaQcQdQIyli21Gu8F2l+nimKHRe+fUNi+MWd1e/u29BYZa+RZ1yxhbHIbFzytg7fAA==".to_owned(),
hash: Some("0000000000000000000000000000000000000000000000000000000000000000".to_owned()),
..Default::default()
})?;
apply_block(&b1, &gva_db)?;
let b2 = DubpBlockV10::from_string_object(&DubpBlockV10Stringified {
number: 2,
version: 10,
median_time: 5_247,
dividend: Some(1000),
transactions: vec![TransactionDocumentV10Stringified {
currency: "test".to_owned(),
blockstamp: "0-0000000000000000000000000000000000000000000000000000000000000000".to_owned(),
locktime: 0,
issuers: vec!["D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx".to_owned()],
inputs: vec!["400:0:T:0000000000000000000000000000000000000000000000000000000000000000:1".to_owned()],
unlocks: vec![],
outputs: vec![
"300:0:SIG(D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx)".to_owned(),
"100:0:SIG(4fHMTFBMo5sTQEc5p1CNWz28S4mnnqdUBmECq1zt4n2m)".to_owned(),
],
comment: "".to_owned(),
signatures: vec![],
hash: Some("0101010101010101010101010101010101010101010101010101010101010101".to_owned()),
}],
inner_hash: Some("0000000A65A12DB95B3153BCD05DB4D5C30CC7F0B1292D9FFBC3DE67F72F6040".to_owned()),
signature: "7B0hvcfajE2G8nBLp0vLVaQcQdQIyli21Gu8F2l+nimKHRe+fUNi+MWd1e/u29BYZa+RZ1yxhbHIbFzytg7fAA==".to_owned(),
hash: Some("0000000000000000000000000000000000000000000000000000000000000000".to_owned()),
..Default::default()
})?;
apply_block(&b2, &gva_db)?;
revert_block(&b2, &gva_db)?;
assert_eq!(gva_db.blockchain_time().count()?, 2);
assert_eq!(gva_db.blockchain_time().get(&U32BE(1))?, Some(5_245));
assert_eq!(gva_db.balances().count()?, 2);
assert_eq!(
gva_db.balances().get(&WalletConditionsV2(s2.clone()))?,
Some(SourceAmountValV2(SourceAmount::with_base0(600)))
);
assert_eq!(
gva_db.balances().get(&WalletConditionsV2(s1.clone()))?,
Some(SourceAmountValV2(SourceAmount::with_base0(400)))
);
assert_eq!(gva_db.gva_utxos().count()?, 2);
assert_eq!(
gva_db
.gva_utxos()
.iter(.., |it| it.collect::<KvResult<Vec<_>>>())?,
vec![
(
GvaUtxoIdDbV1::new(s1.clone(), 1, Hash::default(), 1),
SourceAmountValV2(SourceAmount::with_base0(400))
),
(
GvaUtxoIdDbV1::new(s2.clone(), 1, Hash::default(), 0),
SourceAmountValV2(SourceAmount::with_base0(600))
),
]
);
revert_block(&b1, &gva_db)?;
assert_eq!(gva_db.blockchain_time().count()?, 1);
assert_eq!(gva_db.blockchain_time().get(&U32BE(0))?, Some(5_243));
assert_eq!(gva_db.balances().count()?, 2);
assert_eq!(
gva_db.balances().get(&WalletConditionsV2(s1))?,
Some(SourceAmountValV2(SourceAmount::with_base0(1000)))
);
assert_eq!(
gva_db.balances().get(&WalletConditionsV2(s2))?,
Some(SourceAmountValV2(SourceAmount::with_base0(0)))
);
Ok(())
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment