#![cfg(feature = "sqlite")]
use alloy::primitives::{Address, B256};
use mpp::{
client::tempo::session::store::{
ChannelStore, SqliteChannelStore, SqliteChannelStoreOptions, StoredChannelEntry,
},
protocol::methods::tempo::session::ChannelDescriptor,
};
fn interop_entry(cumulative_amount: u128) -> StoredChannelEntry {
StoredChannelEntry {
channel_id: B256::repeat_byte(0x11),
cumulative_amount,
deposit: 10_000_000,
descriptor: ChannelDescriptor {
authorized_signer: "0x0000000000000000000000000000000000000001".into(),
expiring_nonce_hash: format!("{:#x}", B256::repeat_byte(0x22)),
operator: format!("{:#x}", Address::ZERO),
payee: "0x0000000000000000000000000000000000000002".into(),
payer: "0x0000000000000000000000000000000000000003".into(),
salt: format!("{:#x}", B256::repeat_byte(0x33)),
token: "0x0000000000000000000000000000000000000004".into(),
},
settlement_route: None,
escrow: "0x0000000000000000000000000000000000000005"
.parse()
.unwrap(),
chain_id: 4217,
opened: true,
}
}
#[tokio::test]
#[ignore = "requires MPPX_CHANNEL_DB generated by the MPPx Node SQLite store"]
async fn mppx_and_rust_share_the_same_channel_database() {
let path = std::env::var_os("MPPX_CHANNEL_DB").expect("set MPPX_CHANNEL_DB");
let store = SqliteChannelStore::open(SqliteChannelStoreOptions {
namespace: "https://api.example.com".into(),
path: Some(path.into()),
request_url: None,
})
.unwrap();
let initial = interop_entry(2_000_000);
assert_eq!(store.get(&initial.key()).await.unwrap(), Some(initial));
store.set(&interop_entry(3_000_000)).await.unwrap();
assert_eq!(
store
.get(&interop_entry(0).key())
.await
.unwrap()
.unwrap()
.cumulative_amount,
3_000_000
);
}