stellar-strkey 0.0.16

Encode and decode strkeys for Stellar.
Documentation
use stellar_strkey::*;

#[test]
fn test_strkey_ed25519_public_key_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::PublicKeyEd25519(ed25519::PublicKey([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "PublicKeyEd25519(PublicKey(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_ed25519_private_key_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::PrivateKeyEd25519(ed25519::PrivateKey([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "PrivateKeyEd25519(PrivateKey(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_contract_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::Contract(Contract([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "Contract(Contract(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_hash_x_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::HashX(HashX([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "HashX(HashX(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_pre_auth_tx_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::PreAuthTx(PreAuthTx([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "PreAuthTx(PreAuthTx(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_ed25519_muxed_account_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::MuxedAccountEd25519(ed25519::MuxedAccount {
                ed25519: [
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                ],
                id: 0,
            })
        ),
        "MuxedAccountEd25519(MuxedAccount(0000000000000000000000000000000000000000000000000000000000000000, 0))",
    );
}

#[test]
fn test_strkey_ed25519_signed_payload_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::SignedPayloadEd25519(ed25519::SignedPayload {
                ed25519: [
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                ],
                payload: [1u8, 2, 3, 4].as_slice().try_into().unwrap(),
            })
        ),
        "SignedPayloadEd25519(SignedPayload(0000000000000000000000000000000000000000000000000000000000000000, 01020304))",
    );
}

#[test]
fn test_strkey_liquidity_pool_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::LiquidityPool(LiquidityPool([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "LiquidityPool(LiquidityPool(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_claimable_balance_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::ClaimableBalance(ClaimableBalance::V0([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "ClaimableBalance(ClaimableBalance(V0(0000000000000000000000000000000000000000000000000000000000000000)))",
    );
}

// Inner type debug tests

#[test]
fn test_ed25519_public_key_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::PublicKey([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "PublicKey(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_ed25519_private_key_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::PrivateKey([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "PrivateKey(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_pre_auth_tx_debug() {
    assert_eq!(
        format!(
            "{:?}",
            PreAuthTx([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "PreAuthTx(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_hash_x_debug() {
    assert_eq!(
        format!(
            "{:?}",
            HashX([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "HashX(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_ed25519_muxed_account_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::MuxedAccount {
                ed25519: [
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                ],
                id: 0,
            }
        ),
        "MuxedAccount(0000000000000000000000000000000000000000000000000000000000000000, 0)",
    );
}

#[test]
fn test_ed25519_signed_payload_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::SignedPayload {
                ed25519: [
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                ],
                payload: [1u8, 2, 3, 4].as_slice().try_into().unwrap(),
            }
        ),
        "SignedPayload(0000000000000000000000000000000000000000000000000000000000000000, 01020304)",
    );
}

#[test]
fn test_contract_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Contract([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "Contract(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_liquidity_pool_debug() {
    assert_eq!(
        format!(
            "{:?}",
            LiquidityPool([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "LiquidityPool(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_claimable_balance_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ClaimableBalance::V0([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "ClaimableBalance(V0(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}