mirror of
https://github.com/we-promise/sure.git
synced 2026-04-08 14:54:49 +00:00
* Feat(CoinStats): Scaffold implementation, not yet functional * Feat(CoinStats): Implement crypto wallet balance and transactions * Feat(CoinStats): Add tests, Minor improvements * Feat(CoinStats): Utilize bulk fetch API endpoints * Feat(CoinStats): Migrate strings to i8n * Feat(CoinStats): Fix error handling in wallet link modal * Feat(CoinStats): Implement hourly provider sync job * Feat(CoinStats): Generate docstrings * Fix(CoinStats): Validate API Key on provider update * Fix(Providers): Safely handle race condition in merchance creation * Fix(CoinStats): Don't catch system signals in account processor * Fix(CoinStats): Preload before iterating accounts * Fix(CoinStats): Add no opener / referrer to API dashboard link * Fix(CoinStats): Use strict matching for symbols * Fix(CoinStats): Remove dead code in transactions importer * Fix(CoinStats): Avoid transaction fallback ID collisions * Fix(CoinStats): Improve Blockchains fetch error handling * Fix(CoinStats): Enforce NOT NULL constraint for API Key schema * Fix(CoinStats): Migrate sync status strings to i8n * Fix(CoinStats): Use class name rather than hardcoded string * Fix(CoinStats): Use account currency rather than hardcoded USD * Fix(CoinStats): Migrate from standalone to Provider class * Fix(CoinStats): Fix test failures due to string changes
165 lines
4.4 KiB
Ruby
165 lines
4.4 KiB
Ruby
require "test_helper"
|
|
|
|
class Provider::CoinstatsTest < ActiveSupport::TestCase
|
|
setup do
|
|
@provider = Provider::Coinstats.new("test_api_key")
|
|
end
|
|
|
|
test "extract_wallet_balance finds matching wallet by address and connectionId" do
|
|
bulk_data = [
|
|
{
|
|
blockchain: "ethereum",
|
|
address: "0x123abc",
|
|
connectionId: "ethereum",
|
|
balances: [
|
|
{ coinId: "ethereum", name: "Ethereum", amount: 1.5, price: 2000 }
|
|
]
|
|
},
|
|
{
|
|
blockchain: "bitcoin",
|
|
address: "bc1qxyz",
|
|
connectionId: "bitcoin",
|
|
balances: [
|
|
{ coinId: "bitcoin", name: "Bitcoin", amount: 0.5, price: 50000 }
|
|
]
|
|
}
|
|
]
|
|
|
|
result = @provider.extract_wallet_balance(bulk_data, "0x123abc", "ethereum")
|
|
|
|
assert_equal 1, result.size
|
|
assert_equal "ethereum", result.first[:coinId]
|
|
end
|
|
|
|
test "extract_wallet_balance handles case insensitive matching" do
|
|
bulk_data = [
|
|
{
|
|
blockchain: "Ethereum",
|
|
address: "0x123ABC",
|
|
connectionId: "Ethereum",
|
|
balances: [
|
|
{ coinId: "ethereum", name: "Ethereum", amount: 1.5, price: 2000 }
|
|
]
|
|
}
|
|
]
|
|
|
|
result = @provider.extract_wallet_balance(bulk_data, "0x123abc", "ethereum")
|
|
|
|
assert_equal 1, result.size
|
|
assert_equal "ethereum", result.first[:coinId]
|
|
end
|
|
|
|
test "extract_wallet_balance returns empty array when wallet not found" do
|
|
bulk_data = [
|
|
{
|
|
blockchain: "ethereum",
|
|
address: "0x123abc",
|
|
connectionId: "ethereum",
|
|
balances: [
|
|
{ coinId: "ethereum", name: "Ethereum", amount: 1.5, price: 2000 }
|
|
]
|
|
}
|
|
]
|
|
|
|
result = @provider.extract_wallet_balance(bulk_data, "0xnotfound", "ethereum")
|
|
|
|
assert_equal [], result
|
|
end
|
|
|
|
test "extract_wallet_balance returns empty array for nil bulk_data" do
|
|
result = @provider.extract_wallet_balance(nil, "0x123abc", "ethereum")
|
|
|
|
assert_equal [], result
|
|
end
|
|
|
|
test "extract_wallet_balance returns empty array for non-array bulk_data" do
|
|
result = @provider.extract_wallet_balance({ error: "invalid" }, "0x123abc", "ethereum")
|
|
|
|
assert_equal [], result
|
|
end
|
|
|
|
test "extract_wallet_balance matches by blockchain when connectionId differs" do
|
|
bulk_data = [
|
|
{
|
|
blockchain: "ethereum",
|
|
address: "0x123abc",
|
|
connectionId: "eth-mainnet", # Different connectionId
|
|
balances: [
|
|
{ coinId: "ethereum", name: "Ethereum", amount: 1.5, price: 2000 }
|
|
]
|
|
}
|
|
]
|
|
|
|
result = @provider.extract_wallet_balance(bulk_data, "0x123abc", "ethereum")
|
|
|
|
assert_equal 1, result.size
|
|
end
|
|
|
|
test "extract_wallet_transactions finds matching wallet transactions" do
|
|
bulk_data = [
|
|
{
|
|
blockchain: "ethereum",
|
|
address: "0x123abc",
|
|
connectionId: "ethereum",
|
|
transactions: [
|
|
{ hash: { id: "0xtx1" }, type: "Received", date: "2025-01-01T10:00:00.000Z" },
|
|
{ hash: { id: "0xtx2" }, type: "Sent", date: "2025-01-02T11:00:00.000Z" }
|
|
]
|
|
},
|
|
{
|
|
blockchain: "bitcoin",
|
|
address: "bc1qxyz",
|
|
connectionId: "bitcoin",
|
|
transactions: [
|
|
{ hash: { id: "btctx1" }, type: "Received", date: "2025-01-03T12:00:00.000Z" }
|
|
]
|
|
}
|
|
]
|
|
|
|
result = @provider.extract_wallet_transactions(bulk_data, "0x123abc", "ethereum")
|
|
|
|
assert_equal 2, result.size
|
|
assert_equal "0xtx1", result.first[:hash][:id]
|
|
end
|
|
|
|
test "extract_wallet_transactions returns empty array when wallet not found" do
|
|
bulk_data = [
|
|
{
|
|
blockchain: "ethereum",
|
|
address: "0x123abc",
|
|
connectionId: "ethereum",
|
|
transactions: [
|
|
{ hash: { id: "0xtx1" }, type: "Received" }
|
|
]
|
|
}
|
|
]
|
|
|
|
result = @provider.extract_wallet_transactions(bulk_data, "0xnotfound", "ethereum")
|
|
|
|
assert_equal [], result
|
|
end
|
|
|
|
test "extract_wallet_transactions returns empty array for nil bulk_data" do
|
|
result = @provider.extract_wallet_transactions(nil, "0x123abc", "ethereum")
|
|
|
|
assert_equal [], result
|
|
end
|
|
|
|
test "extract_wallet_transactions handles case insensitive matching" do
|
|
bulk_data = [
|
|
{
|
|
blockchain: "Ethereum",
|
|
address: "0x123ABC",
|
|
connectionId: "Ethereum",
|
|
transactions: [
|
|
{ hash: { id: "0xtx1" }, type: "Received" }
|
|
]
|
|
}
|
|
]
|
|
|
|
result = @provider.extract_wallet_transactions(bulk_data, "0x123abc", "ethereum")
|
|
|
|
assert_equal 1, result.size
|
|
end
|
|
end
|