...
This commit is contained in:
@@ -7,19 +7,24 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_asset_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut asset_db := DBAsset{db: &mydb}
|
||||
mut asset_db := DBAsset{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test creating a new asset with all fields
|
||||
mut asset := asset_db.new(
|
||||
name: 'Test Token'
|
||||
description: 'A test token for unit testing'
|
||||
address: 'GBTC...XYZ123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: {'symbol': 'TEST', 'website': 'https://test.com'}
|
||||
name: 'Test Token'
|
||||
description: 'A test token for unit testing'
|
||||
address: 'GBTC...XYZ123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: {
|
||||
'symbol': 'TEST'
|
||||
'website': 'https://test.com'
|
||||
}
|
||||
administrators: [u32(1), 2, 3]
|
||||
min_signatures: 2
|
||||
)!
|
||||
@@ -44,37 +49,43 @@ fn test_asset_new() {
|
||||
|
||||
fn test_asset_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut asset_db := DBAsset{db: &mydb}
|
||||
mut asset_db := DBAsset{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create a complex asset with all field types
|
||||
mut original_asset := asset_db.new(
|
||||
name: 'Encoding Test Asset'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
address: 'GABCD...XYZ789'
|
||||
asset_type: 'nft'
|
||||
issuer: 999
|
||||
supply: 5000000.0
|
||||
decimals: 6
|
||||
is_frozen: true
|
||||
metadata: {
|
||||
'symbol': 'ETA'
|
||||
'website': 'https://example.com'
|
||||
name: 'Encoding Test Asset'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
address: 'GABCD...XYZ789'
|
||||
asset_type: 'nft'
|
||||
issuer: 999
|
||||
supply: 5000000.0
|
||||
decimals: 6
|
||||
is_frozen: true
|
||||
metadata: {
|
||||
'symbol': 'ETA'
|
||||
'website': 'https://example.com'
|
||||
'description': 'Extended test asset'
|
||||
'category': 'utility'
|
||||
'version': '1.0'
|
||||
'category': 'utility'
|
||||
'version': '1.0'
|
||||
}
|
||||
administrators: [u32(10), 20, 30, 40]
|
||||
min_signatures: 3
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_asset.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoded_asset := Asset{}
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_asset := Asset{
|
||||
address: ''
|
||||
asset_type: ''
|
||||
issuer: 0
|
||||
}
|
||||
asset_db.load(mut decoded_asset, mut decoder_obj)!
|
||||
|
||||
// Verify all fields match after encoding/decoding
|
||||
@@ -101,19 +112,24 @@ fn test_asset_encoding_decoding() {
|
||||
|
||||
fn test_asset_set_and_get() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut asset_db := DBAsset{db: &mydb}
|
||||
mut asset_db := DBAsset{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create asset
|
||||
mut asset := asset_db.new(
|
||||
name: 'DB Test Asset'
|
||||
description: 'Testing database operations'
|
||||
address: 'GTEST...DB123'
|
||||
asset_type: 'token'
|
||||
issuer: 42
|
||||
supply: 100000.0
|
||||
decimals: 2
|
||||
is_frozen: false
|
||||
metadata: {'currency': 'EUR', 'region': 'EU'}
|
||||
name: 'DB Test Asset'
|
||||
description: 'Testing database operations'
|
||||
address: 'GTEST...DB123'
|
||||
asset_type: 'token'
|
||||
issuer: 42
|
||||
supply: 100000.0
|
||||
decimals: 2
|
||||
is_frozen: false
|
||||
metadata: {
|
||||
'currency': 'EUR'
|
||||
'region': 'EU'
|
||||
}
|
||||
administrators: [u32(5), 10]
|
||||
min_signatures: 1
|
||||
)!
|
||||
@@ -149,19 +165,23 @@ fn test_asset_set_and_get() {
|
||||
|
||||
fn test_asset_update() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut asset_db := DBAsset{db: &mydb}
|
||||
mut asset_db := DBAsset{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save an asset
|
||||
mut asset := asset_db.new(
|
||||
name: 'Original Asset'
|
||||
description: 'Original description'
|
||||
address: 'GORIG...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: {'version': '1.0'}
|
||||
name: 'Original Asset'
|
||||
description: 'Original description'
|
||||
address: 'GORIG...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: {
|
||||
'version': '1.0'
|
||||
}
|
||||
administrators: [u32(1)]
|
||||
min_signatures: 1
|
||||
)!
|
||||
@@ -175,7 +195,10 @@ fn test_asset_update() {
|
||||
asset.description = 'Updated description'
|
||||
asset.supply = 2000.0
|
||||
asset.is_frozen = true
|
||||
asset.metadata = {'version': '2.0', 'status': 'updated'}
|
||||
asset.metadata = {
|
||||
'version': '2.0'
|
||||
'status': 'updated'
|
||||
}
|
||||
asset.administrators = [u32(1), 2, 3]
|
||||
asset.min_signatures = 2
|
||||
|
||||
@@ -200,7 +223,9 @@ fn test_asset_update() {
|
||||
|
||||
fn test_asset_exist_and_delete() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut asset_db := DBAsset{db: &mydb}
|
||||
mut asset_db := DBAsset{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test non-existent asset
|
||||
exists := asset_db.exist(999)!
|
||||
@@ -208,15 +233,15 @@ fn test_asset_exist_and_delete() {
|
||||
|
||||
// Create and save an asset
|
||||
mut asset := asset_db.new(
|
||||
name: 'To Be Deleted'
|
||||
description: 'This asset will be deleted'
|
||||
address: 'GDEL...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1.0
|
||||
decimals: 0
|
||||
is_frozen: false
|
||||
metadata: map[string]string{}
|
||||
name: 'To Be Deleted'
|
||||
description: 'This asset will be deleted'
|
||||
address: 'GDEL...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1.0
|
||||
decimals: 0
|
||||
is_frozen: false
|
||||
metadata: map[string]string{}
|
||||
administrators: []u32{}
|
||||
min_signatures: 0
|
||||
)!
|
||||
@@ -243,7 +268,9 @@ fn test_asset_exist_and_delete() {
|
||||
|
||||
fn test_asset_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut asset_db := DBAsset{db: &mydb}
|
||||
mut asset_db := DBAsset{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Initially should be empty
|
||||
initial_list := asset_db.list()!
|
||||
@@ -251,29 +278,34 @@ fn test_asset_list() {
|
||||
|
||||
// Create multiple assets
|
||||
mut asset1 := asset_db.new(
|
||||
name: 'Asset 1'
|
||||
description: 'First asset'
|
||||
address: 'GFIRST...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: {'type': 'utility'}
|
||||
name: 'Asset 1'
|
||||
description: 'First asset'
|
||||
address: 'GFIRST...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: {
|
||||
'type': 'utility'
|
||||
}
|
||||
administrators: [u32(1)]
|
||||
min_signatures: 1
|
||||
)!
|
||||
|
||||
mut asset2 := asset_db.new(
|
||||
name: 'Asset 2'
|
||||
description: 'Second asset'
|
||||
address: 'GSECOND...456'
|
||||
asset_type: 'nft'
|
||||
issuer: 2
|
||||
supply: 100.0
|
||||
decimals: 0
|
||||
is_frozen: true
|
||||
metadata: {'type': 'collectible', 'rarity': 'rare'}
|
||||
name: 'Asset 2'
|
||||
description: 'Second asset'
|
||||
address: 'GSECOND...456'
|
||||
asset_type: 'nft'
|
||||
issuer: 2
|
||||
supply: 100.0
|
||||
decimals: 0
|
||||
is_frozen: true
|
||||
metadata: {
|
||||
'type': 'collectible'
|
||||
'rarity': 'rare'
|
||||
}
|
||||
administrators: [u32(1), 2]
|
||||
min_signatures: 2
|
||||
)!
|
||||
@@ -313,19 +345,21 @@ fn test_asset_list() {
|
||||
|
||||
fn test_asset_edge_cases() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut asset_db := DBAsset{db: &mydb}
|
||||
mut asset_db := DBAsset{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test empty/minimal asset
|
||||
mut minimal_asset := asset_db.new(
|
||||
name: ''
|
||||
description: ''
|
||||
address: ''
|
||||
asset_type: ''
|
||||
issuer: 0
|
||||
supply: 0.0
|
||||
decimals: 0
|
||||
is_frozen: false
|
||||
metadata: map[string]string{}
|
||||
name: ''
|
||||
description: ''
|
||||
address: ''
|
||||
asset_type: ''
|
||||
issuer: 0
|
||||
supply: 0.0
|
||||
decimals: 0
|
||||
is_frozen: false
|
||||
metadata: map[string]string{}
|
||||
administrators: []u32{}
|
||||
min_signatures: 0
|
||||
)!
|
||||
@@ -349,15 +383,15 @@ fn test_asset_edge_cases() {
|
||||
}
|
||||
|
||||
mut large_asset := asset_db.new(
|
||||
name: 'Large Metadata Asset'
|
||||
description: 'Asset with large metadata'
|
||||
address: 'GLARGE...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: large_metadata
|
||||
name: 'Large Metadata Asset'
|
||||
description: 'Asset with large metadata'
|
||||
address: 'GLARGE...123'
|
||||
asset_type: 'token'
|
||||
issuer: 1
|
||||
supply: 1000.0
|
||||
decimals: 8
|
||||
is_frozen: false
|
||||
metadata: large_metadata
|
||||
administrators: []u32{}
|
||||
min_signatures: 0
|
||||
)!
|
||||
@@ -368,4 +402,4 @@ fn test_asset_edge_cases() {
|
||||
assert retrieved_large.metadata.len == 100
|
||||
assert retrieved_large.metadata['key_0'] == 'value_0'
|
||||
assert retrieved_large.metadata['key_99'] == 'value_99'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,53 +7,58 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_dnszone_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut dns_db := DBDNSZone{db: &mydb}
|
||||
mut dns_db := DBDNSZone{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create test DNS zone with records and SOA
|
||||
dns_record1 := DNSRecord{
|
||||
subdomain: 'www'
|
||||
subdomain: 'www'
|
||||
record_type: .a
|
||||
value: '192.168.1.1'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
value: '192.168.1.1'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
is_wildcard: false
|
||||
}
|
||||
|
||||
dns_record2 := DNSRecord{
|
||||
subdomain: 'mail'
|
||||
subdomain: 'mail'
|
||||
record_type: .mx
|
||||
value: 'mail.example.com'
|
||||
priority: 10
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
value: 'mail.example.com'
|
||||
priority: 10
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
is_wildcard: false
|
||||
}
|
||||
|
||||
soa_record := SOARecord{
|
||||
zone_id: 1
|
||||
primary_ns: 'ns1.example.com'
|
||||
zone_id: 1
|
||||
primary_ns: 'ns1.example.com'
|
||||
admin_email: 'admin@example.com'
|
||||
serial: 2023120101
|
||||
refresh: 3600
|
||||
retry: 1800
|
||||
expire: 604800
|
||||
serial: 2023120101
|
||||
refresh: 3600
|
||||
retry: 1800
|
||||
expire: 604800
|
||||
minimum_ttl: 86400
|
||||
is_active: true
|
||||
is_active: true
|
||||
}
|
||||
|
||||
mut dnszone := dns_db.new(
|
||||
name: 'Test DNS Zone'
|
||||
description: 'A test DNS zone for unit testing'
|
||||
domain: 'example.com'
|
||||
dnsrecords: [dns_record1, dns_record2]
|
||||
name: 'Test DNS Zone'
|
||||
description: 'A test DNS zone for unit testing'
|
||||
domain: 'example.com'
|
||||
dnsrecords: [dns_record1, dns_record2]
|
||||
administrators: [u32(1), 2, 3]
|
||||
status: .active
|
||||
status: .active
|
||||
min_signatures: 2
|
||||
metadata: {'zone_type': 'primary', 'provider': 'test'}
|
||||
soarecord: [soa_record]
|
||||
metadata: {
|
||||
'zone_type': 'primary'
|
||||
'provider': 'test'
|
||||
}
|
||||
soarecord: [soa_record]
|
||||
)!
|
||||
|
||||
// Verify the DNS zone was created with correct values
|
||||
@@ -75,102 +80,106 @@ fn test_dnszone_new() {
|
||||
|
||||
fn test_dnszone_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut dns_db := DBDNSZone{db: &mydb}
|
||||
mut dns_db := DBDNSZone{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create a complex DNS zone with multiple record types
|
||||
records := [
|
||||
DNSRecord{
|
||||
subdomain: '@'
|
||||
subdomain: '@'
|
||||
record_type: .a
|
||||
value: '203.0.113.1'
|
||||
priority: 0
|
||||
ttl: 300
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
value: '203.0.113.1'
|
||||
priority: 0
|
||||
ttl: 300
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
is_wildcard: false
|
||||
},
|
||||
DNSRecord{
|
||||
subdomain: 'www'
|
||||
subdomain: 'www'
|
||||
record_type: .cname
|
||||
value: 'example.com'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
value: 'example.com'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
is_wildcard: false
|
||||
},
|
||||
DNSRecord{
|
||||
subdomain: '*'
|
||||
subdomain: '*'
|
||||
record_type: .a
|
||||
value: '203.0.113.2'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: false
|
||||
cat: .ipv4
|
||||
value: '203.0.113.2'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: false
|
||||
cat: .ipv4
|
||||
is_wildcard: true
|
||||
},
|
||||
DNSRecord{
|
||||
subdomain: 'ipv6'
|
||||
subdomain: 'ipv6'
|
||||
record_type: .aaaa
|
||||
value: '2001:db8::1'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv6
|
||||
value: '2001:db8::1'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv6
|
||||
is_wildcard: false
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
soa_records := [
|
||||
SOARecord{
|
||||
zone_id: 1
|
||||
primary_ns: 'ns1.test.com'
|
||||
zone_id: 1
|
||||
primary_ns: 'ns1.test.com'
|
||||
admin_email: 'dns-admin@test.com'
|
||||
serial: 2023120201
|
||||
refresh: 7200
|
||||
retry: 3600
|
||||
expire: 1209600
|
||||
serial: 2023120201
|
||||
refresh: 7200
|
||||
retry: 3600
|
||||
expire: 1209600
|
||||
minimum_ttl: 300
|
||||
is_active: true
|
||||
is_active: true
|
||||
},
|
||||
SOARecord{
|
||||
zone_id: 2
|
||||
primary_ns: 'ns2.test.com'
|
||||
zone_id: 2
|
||||
primary_ns: 'ns2.test.com'
|
||||
admin_email: 'backup-admin@test.com'
|
||||
serial: 2023120202
|
||||
refresh: 7200
|
||||
retry: 3600
|
||||
expire: 1209600
|
||||
serial: 2023120202
|
||||
refresh: 7200
|
||||
retry: 3600
|
||||
expire: 1209600
|
||||
minimum_ttl: 300
|
||||
is_active: false
|
||||
}
|
||||
is_active: false
|
||||
},
|
||||
]
|
||||
|
||||
mut original_zone := dns_db.new(
|
||||
name: 'Encoding Test Zone'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
domain: 'test.com'
|
||||
dnsrecords: records
|
||||
name: 'Encoding Test Zone'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
domain: 'test.com'
|
||||
dnsrecords: records
|
||||
administrators: [u32(10), 20, 30]
|
||||
status: .suspended
|
||||
status: .suspended
|
||||
min_signatures: 3
|
||||
metadata: {
|
||||
'zone_type': 'secondary'
|
||||
'provider': 'test_provider'
|
||||
metadata: {
|
||||
'zone_type': 'secondary'
|
||||
'provider': 'test_provider'
|
||||
'environment': 'staging'
|
||||
'auto_dnssec': 'true'
|
||||
}
|
||||
soarecord: soa_records
|
||||
soarecord: soa_records
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_zone.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoded_zone := DNSZone{}
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_zone := DNSZone{
|
||||
domain: ''
|
||||
}
|
||||
dns_db.load(mut decoded_zone, mut decoder_obj)!
|
||||
|
||||
// Verify all fields match after encoding/decoding
|
||||
@@ -222,30 +231,34 @@ fn test_dnszone_encoding_decoding() {
|
||||
|
||||
fn test_dnszone_set_and_get() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut dns_db := DBDNSZone{db: &mydb}
|
||||
mut dns_db := DBDNSZone{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create simple DNS zone
|
||||
record := DNSRecord{
|
||||
subdomain: 'api'
|
||||
subdomain: 'api'
|
||||
record_type: .a
|
||||
value: '192.168.1.100'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
value: '192.168.1.100'
|
||||
priority: 0
|
||||
ttl: 3600
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
is_wildcard: false
|
||||
}
|
||||
|
||||
mut dnszone := dns_db.new(
|
||||
name: 'DB Test Zone'
|
||||
description: 'Testing database operations'
|
||||
domain: 'dbtest.com'
|
||||
dnsrecords: [record]
|
||||
name: 'DB Test Zone'
|
||||
description: 'Testing database operations'
|
||||
domain: 'dbtest.com'
|
||||
dnsrecords: [record]
|
||||
administrators: [u32(5)]
|
||||
status: .active
|
||||
status: .active
|
||||
min_signatures: 1
|
||||
metadata: {'test': 'true'}
|
||||
soarecord: []SOARecord{}
|
||||
metadata: {
|
||||
'test': 'true'
|
||||
}
|
||||
soarecord: []SOARecord{}
|
||||
)!
|
||||
|
||||
// Save the DNS zone
|
||||
@@ -276,19 +289,23 @@ fn test_dnszone_set_and_get() {
|
||||
|
||||
fn test_dnszone_update() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut dns_db := DBDNSZone{db: &mydb}
|
||||
mut dns_db := DBDNSZone{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save a DNS zone
|
||||
mut dnszone := dns_db.new(
|
||||
name: 'Original Zone'
|
||||
description: 'Original description'
|
||||
domain: 'original.com'
|
||||
dnsrecords: []DNSRecord{}
|
||||
name: 'Original Zone'
|
||||
description: 'Original description'
|
||||
domain: 'original.com'
|
||||
dnsrecords: []DNSRecord{}
|
||||
administrators: [u32(1)]
|
||||
status: .active
|
||||
status: .active
|
||||
min_signatures: 1
|
||||
metadata: {'version': '1.0'}
|
||||
soarecord: []SOARecord{}
|
||||
metadata: {
|
||||
'version': '1.0'
|
||||
}
|
||||
soarecord: []SOARecord{}
|
||||
)!
|
||||
|
||||
dnszone = dns_db.set(dnszone)!
|
||||
@@ -297,13 +314,13 @@ fn test_dnszone_update() {
|
||||
|
||||
// Update the DNS zone
|
||||
new_record := DNSRecord{
|
||||
subdomain: 'updated'
|
||||
subdomain: 'updated'
|
||||
record_type: .a
|
||||
value: '10.0.0.1'
|
||||
priority: 0
|
||||
ttl: 300
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
value: '10.0.0.1'
|
||||
priority: 0
|
||||
ttl: 300
|
||||
is_active: true
|
||||
cat: .ipv4
|
||||
is_wildcard: false
|
||||
}
|
||||
|
||||
@@ -312,7 +329,10 @@ fn test_dnszone_update() {
|
||||
dnszone.domain = 'updated.com'
|
||||
dnszone.dnsrecords = [new_record]
|
||||
dnszone.status = .suspended
|
||||
dnszone.metadata = {'version': '2.0', 'updated': 'true'}
|
||||
dnszone.metadata = {
|
||||
'version': '2.0'
|
||||
'updated': 'true'
|
||||
}
|
||||
dnszone.min_signatures = 2
|
||||
|
||||
dnszone = dns_db.set(dnszone)!
|
||||
@@ -336,7 +356,9 @@ fn test_dnszone_update() {
|
||||
|
||||
fn test_dnszone_exist_and_delete() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut dns_db := DBDNSZone{db: &mydb}
|
||||
mut dns_db := DBDNSZone{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test non-existent DNS zone
|
||||
exists := dns_db.exist(999)!
|
||||
@@ -344,15 +366,15 @@ fn test_dnszone_exist_and_delete() {
|
||||
|
||||
// Create and save a DNS zone
|
||||
mut dnszone := dns_db.new(
|
||||
name: 'To Be Deleted'
|
||||
description: 'This DNS zone will be deleted'
|
||||
domain: 'delete.com'
|
||||
dnsrecords: []DNSRecord{}
|
||||
name: 'To Be Deleted'
|
||||
description: 'This DNS zone will be deleted'
|
||||
domain: 'delete.com'
|
||||
dnsrecords: []DNSRecord{}
|
||||
administrators: []u32{}
|
||||
status: .archived
|
||||
status: .archived
|
||||
min_signatures: 0
|
||||
metadata: map[string]string{}
|
||||
soarecord: []SOARecord{}
|
||||
metadata: map[string]string{}
|
||||
soarecord: []SOARecord{}
|
||||
)!
|
||||
|
||||
dnszone = dns_db.set(dnszone)!
|
||||
@@ -377,7 +399,9 @@ fn test_dnszone_exist_and_delete() {
|
||||
|
||||
fn test_dnszone_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut dns_db := DBDNSZone{db: &mydb}
|
||||
mut dns_db := DBDNSZone{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Initially should be empty
|
||||
initial_list := dns_db.list()!
|
||||
@@ -385,27 +409,31 @@ fn test_dnszone_list() {
|
||||
|
||||
// Create multiple DNS zones
|
||||
mut zone1 := dns_db.new(
|
||||
name: 'Zone 1'
|
||||
description: 'First zone'
|
||||
domain: 'zone1.com'
|
||||
dnsrecords: []DNSRecord{}
|
||||
name: 'Zone 1'
|
||||
description: 'First zone'
|
||||
domain: 'zone1.com'
|
||||
dnsrecords: []DNSRecord{}
|
||||
administrators: [u32(1)]
|
||||
status: .active
|
||||
status: .active
|
||||
min_signatures: 1
|
||||
metadata: {'type': 'primary'}
|
||||
soarecord: []SOARecord{}
|
||||
metadata: {
|
||||
'type': 'primary'
|
||||
}
|
||||
soarecord: []SOARecord{}
|
||||
)!
|
||||
|
||||
mut zone2 := dns_db.new(
|
||||
name: 'Zone 2'
|
||||
description: 'Second zone'
|
||||
domain: 'zone2.net'
|
||||
dnsrecords: []DNSRecord{}
|
||||
name: 'Zone 2'
|
||||
description: 'Second zone'
|
||||
domain: 'zone2.net'
|
||||
dnsrecords: []DNSRecord{}
|
||||
administrators: [u32(1), 2]
|
||||
status: .suspended
|
||||
status: .suspended
|
||||
min_signatures: 2
|
||||
metadata: {'type': 'secondary'}
|
||||
soarecord: []SOARecord{}
|
||||
metadata: {
|
||||
'type': 'secondary'
|
||||
}
|
||||
soarecord: []SOARecord{}
|
||||
)!
|
||||
|
||||
// Save both zones
|
||||
@@ -441,7 +469,9 @@ fn test_dnszone_list() {
|
||||
|
||||
fn test_dnszone_record_types() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut dns_db := DBDNSZone{db: &mydb}
|
||||
mut dns_db := DBDNSZone{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test all DNS record types
|
||||
record_types := [NameType.a, .aaaa, .cname, .mx, .txt, .srv, .ptr, .ns]
|
||||
@@ -451,27 +481,27 @@ fn test_dnszone_record_types() {
|
||||
for i, rtype in record_types {
|
||||
cat := record_cats[i % record_cats.len]
|
||||
records << DNSRecord{
|
||||
subdomain: 'test${i}'
|
||||
subdomain: 'test${i}'
|
||||
record_type: rtype
|
||||
value: 'value${i}'
|
||||
priority: u32(i)
|
||||
ttl: u32(300 + i * 100)
|
||||
is_active: i % 2 == 0
|
||||
cat: cat
|
||||
value: 'value${i}'
|
||||
priority: u32(i)
|
||||
ttl: u32(300 + i * 100)
|
||||
is_active: i % 2 == 0
|
||||
cat: cat
|
||||
is_wildcard: i > 4
|
||||
}
|
||||
}
|
||||
|
||||
mut zone := dns_db.new(
|
||||
name: 'Record Types Test'
|
||||
description: 'Testing all record types'
|
||||
domain: 'recordtest.com'
|
||||
dnsrecords: records
|
||||
name: 'Record Types Test'
|
||||
description: 'Testing all record types'
|
||||
domain: 'recordtest.com'
|
||||
dnsrecords: records
|
||||
administrators: []u32{}
|
||||
status: .active
|
||||
status: .active
|
||||
min_signatures: 0
|
||||
metadata: map[string]string{}
|
||||
soarecord: []SOARecord{}
|
||||
metadata: map[string]string{}
|
||||
soarecord: []SOARecord{}
|
||||
)!
|
||||
|
||||
zone = dns_db.set(zone)!
|
||||
@@ -485,4 +515,4 @@ fn test_dnszone_record_types() {
|
||||
assert record.is_active == (i % 2 == 0)
|
||||
assert record.is_wildcard == (i > 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,28 +7,30 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_group_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create test group with configuration
|
||||
config := GroupConfig{
|
||||
max_members: 100
|
||||
allow_guests: true
|
||||
auto_approve: false
|
||||
max_members: 100
|
||||
allow_guests: true
|
||||
auto_approve: false
|
||||
require_invite: true
|
||||
}
|
||||
|
||||
mut group := group_db.new(
|
||||
name: 'Test Group'
|
||||
description: 'A test group for unit testing'
|
||||
group_name: 'developers'
|
||||
dnsrecords: [u32(1), 2, 3]
|
||||
name: 'Test Group'
|
||||
description: 'A test group for unit testing'
|
||||
group_name: 'developers'
|
||||
dnsrecords: [u32(1), 2, 3]
|
||||
administrators: [u32(10), 20]
|
||||
min_signatures: 2
|
||||
config: config
|
||||
status: .active
|
||||
visibility: .private
|
||||
created: 1234567890
|
||||
updated: 1234567891
|
||||
config: config
|
||||
status: .active
|
||||
visibility: .private
|
||||
created: 1234567890
|
||||
updated: 1234567891
|
||||
)!
|
||||
|
||||
// Verify the group was created with correct values
|
||||
@@ -54,38 +56,42 @@ fn test_group_new() {
|
||||
|
||||
fn test_group_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create a complex group
|
||||
config := GroupConfig{
|
||||
max_members: 500
|
||||
allow_guests: false
|
||||
auto_approve: true
|
||||
max_members: 500
|
||||
allow_guests: false
|
||||
auto_approve: true
|
||||
require_invite: false
|
||||
}
|
||||
|
||||
mut original_group := group_db.new(
|
||||
name: 'Encoding Test Group'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
group_name: 'encoding_test_group'
|
||||
dnsrecords: [u32(100), 200, 300, 400, 500]
|
||||
name: 'Encoding Test Group'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
group_name: 'encoding_test_group'
|
||||
dnsrecords: [u32(100), 200, 300, 400, 500]
|
||||
administrators: [u32(1), 5, 10, 15, 20, 25]
|
||||
min_signatures: 3
|
||||
config: config
|
||||
status: .suspended
|
||||
visibility: .unlisted
|
||||
created: 1700000000
|
||||
updated: 1700000001
|
||||
config: config
|
||||
status: .suspended
|
||||
visibility: .unlisted
|
||||
created: 1700000000
|
||||
updated: 1700000001
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_group.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoded_group := Group{}
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_group := Group{
|
||||
group_name: ''
|
||||
}
|
||||
group_db.load(mut decoded_group, mut decoder_obj)!
|
||||
|
||||
// Verify all fields match after encoding/decoding
|
||||
@@ -117,28 +123,30 @@ fn test_group_encoding_decoding() {
|
||||
|
||||
fn test_group_set_and_get() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create group
|
||||
config := GroupConfig{
|
||||
max_members: 50
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
max_members: 50
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
require_invite: false
|
||||
}
|
||||
|
||||
mut group := group_db.new(
|
||||
name: 'DB Test Group'
|
||||
description: 'Testing database operations'
|
||||
group_name: 'db_test'
|
||||
dnsrecords: [u32(1)]
|
||||
name: 'DB Test Group'
|
||||
description: 'Testing database operations'
|
||||
group_name: 'db_test'
|
||||
dnsrecords: [u32(1)]
|
||||
administrators: [u32(5), 10]
|
||||
min_signatures: 1
|
||||
config: config
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
config: config
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
)!
|
||||
|
||||
// Save the group
|
||||
@@ -172,28 +180,30 @@ fn test_group_set_and_get() {
|
||||
|
||||
fn test_group_update() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save a group
|
||||
config := GroupConfig{
|
||||
max_members: 25
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
max_members: 25
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
require_invite: true
|
||||
}
|
||||
|
||||
mut group := group_db.new(
|
||||
name: 'Original Group'
|
||||
description: 'Original description'
|
||||
group_name: 'original'
|
||||
dnsrecords: []u32{}
|
||||
name: 'Original Group'
|
||||
description: 'Original description'
|
||||
group_name: 'original'
|
||||
dnsrecords: []u32{}
|
||||
administrators: [u32(1)]
|
||||
min_signatures: 1
|
||||
config: config
|
||||
status: .active
|
||||
visibility: .private
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
config: config
|
||||
status: .active
|
||||
visibility: .private
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
)!
|
||||
|
||||
group = group_db.set(group)!
|
||||
@@ -202,9 +212,9 @@ fn test_group_update() {
|
||||
|
||||
// Update the group
|
||||
new_config := GroupConfig{
|
||||
max_members: 200
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
max_members: 200
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
require_invite: false
|
||||
}
|
||||
|
||||
@@ -242,7 +252,9 @@ fn test_group_update() {
|
||||
|
||||
fn test_group_exist_and_delete() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test non-existent group
|
||||
exists := group_db.exist(999)!
|
||||
@@ -250,24 +262,24 @@ fn test_group_exist_and_delete() {
|
||||
|
||||
// Create and save a group
|
||||
config := GroupConfig{
|
||||
max_members: 10
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
max_members: 10
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
require_invite: true
|
||||
}
|
||||
|
||||
mut group := group_db.new(
|
||||
name: 'To Be Deleted'
|
||||
description: 'This group will be deleted'
|
||||
group_name: 'delete_me'
|
||||
dnsrecords: []u32{}
|
||||
name: 'To Be Deleted'
|
||||
description: 'This group will be deleted'
|
||||
group_name: 'delete_me'
|
||||
dnsrecords: []u32{}
|
||||
administrators: []u32{}
|
||||
min_signatures: 0
|
||||
config: config
|
||||
status: .archived
|
||||
visibility: .private
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
config: config
|
||||
status: .archived
|
||||
visibility: .private
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
)!
|
||||
|
||||
group = group_db.set(group)!
|
||||
@@ -292,7 +304,9 @@ fn test_group_exist_and_delete() {
|
||||
|
||||
fn test_group_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Initially should be empty
|
||||
initial_list := group_db.list()!
|
||||
@@ -300,45 +314,45 @@ fn test_group_list() {
|
||||
|
||||
// Create multiple groups
|
||||
config1 := GroupConfig{
|
||||
max_members: 100
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
max_members: 100
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
require_invite: false
|
||||
}
|
||||
|
||||
config2 := GroupConfig{
|
||||
max_members: 50
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
max_members: 50
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
require_invite: true
|
||||
}
|
||||
|
||||
mut group1 := group_db.new(
|
||||
name: 'Group 1'
|
||||
description: 'First group'
|
||||
group_name: 'group1'
|
||||
dnsrecords: [u32(1)]
|
||||
name: 'Group 1'
|
||||
description: 'First group'
|
||||
group_name: 'group1'
|
||||
dnsrecords: [u32(1)]
|
||||
administrators: [u32(1)]
|
||||
min_signatures: 1
|
||||
config: config1
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
config: config1
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
)!
|
||||
|
||||
mut group2 := group_db.new(
|
||||
name: 'Group 2'
|
||||
description: 'Second group'
|
||||
group_name: 'group2'
|
||||
dnsrecords: [u32(1), 2]
|
||||
name: 'Group 2'
|
||||
description: 'Second group'
|
||||
group_name: 'group2'
|
||||
dnsrecords: [u32(1), 2]
|
||||
administrators: [u32(1), 2]
|
||||
min_signatures: 2
|
||||
config: config2
|
||||
status: .inactive
|
||||
visibility: .private
|
||||
created: 1234567891
|
||||
updated: 1234567891
|
||||
config: config2
|
||||
status: .inactive
|
||||
visibility: .private
|
||||
created: 1234567891
|
||||
updated: 1234567891
|
||||
)!
|
||||
|
||||
// Save both groups
|
||||
@@ -376,7 +390,9 @@ fn test_group_list() {
|
||||
|
||||
fn test_group_status_and_visibility() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test all status values
|
||||
statuses := [GroupStatus.active, .inactive, .suspended, .archived]
|
||||
@@ -386,24 +402,24 @@ fn test_group_status_and_visibility() {
|
||||
visibility := visibilities[i % visibilities.len]
|
||||
|
||||
config := GroupConfig{
|
||||
max_members: u32(10 + i)
|
||||
allow_guests: i % 2 == 0
|
||||
auto_approve: i % 2 == 1
|
||||
max_members: u32(10 + i)
|
||||
allow_guests: i % 2 == 0
|
||||
auto_approve: i % 2 == 1
|
||||
require_invite: i % 3 == 0
|
||||
}
|
||||
|
||||
mut group := group_db.new(
|
||||
name: 'Status Test Group ${i}'
|
||||
description: 'Testing ${status} and ${visibility}'
|
||||
group_name: 'status_test_${i}'
|
||||
dnsrecords: []u32{}
|
||||
name: 'Status Test Group ${i}'
|
||||
description: 'Testing ${status} and ${visibility}'
|
||||
group_name: 'status_test_${i}'
|
||||
dnsrecords: []u32{}
|
||||
administrators: []u32{}
|
||||
min_signatures: 0
|
||||
config: config
|
||||
status: status
|
||||
visibility: visibility
|
||||
created: u64(1234567890 + i)
|
||||
updated: u64(1234567890 + i)
|
||||
config: config
|
||||
status: status
|
||||
visibility: visibility
|
||||
created: u64(1234567890 + i)
|
||||
updated: u64(1234567890 + i)
|
||||
)!
|
||||
|
||||
group = group_db.set(group)!
|
||||
@@ -417,28 +433,30 @@ fn test_group_status_and_visibility() {
|
||||
|
||||
fn test_group_edge_cases() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut group_db := DBGroup{db: &mydb}
|
||||
mut group_db := DBGroup{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test minimal group
|
||||
minimal_config := GroupConfig{
|
||||
max_members: 0
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
max_members: 0
|
||||
allow_guests: false
|
||||
auto_approve: false
|
||||
require_invite: false
|
||||
}
|
||||
|
||||
mut minimal_group := group_db.new(
|
||||
name: ''
|
||||
description: ''
|
||||
group_name: ''
|
||||
dnsrecords: []u32{}
|
||||
name: ''
|
||||
description: ''
|
||||
group_name: ''
|
||||
dnsrecords: []u32{}
|
||||
administrators: []u32{}
|
||||
min_signatures: 0
|
||||
config: minimal_config
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 0
|
||||
updated: 0
|
||||
config: minimal_config
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 0
|
||||
updated: 0
|
||||
)!
|
||||
|
||||
minimal_group = group_db.set(minimal_group)!
|
||||
@@ -456,24 +474,24 @@ fn test_group_edge_cases() {
|
||||
large_administrators := []u32{len: 100, init: u32(index + 1000)}
|
||||
|
||||
large_config := GroupConfig{
|
||||
max_members: 99999
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
max_members: 99999
|
||||
allow_guests: true
|
||||
auto_approve: true
|
||||
require_invite: true
|
||||
}
|
||||
|
||||
mut large_group := group_db.new(
|
||||
name: 'Large Group'
|
||||
description: 'Group with large arrays'
|
||||
group_name: 'large_group'
|
||||
dnsrecords: large_dns_records
|
||||
name: 'Large Group'
|
||||
description: 'Group with large arrays'
|
||||
group_name: 'large_group'
|
||||
dnsrecords: large_dns_records
|
||||
administrators: large_administrators
|
||||
min_signatures: 50
|
||||
config: large_config
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
config: large_config
|
||||
status: .active
|
||||
visibility: .public
|
||||
created: 1234567890
|
||||
updated: 1234567890
|
||||
)!
|
||||
|
||||
large_group = group_db.set(large_group)!
|
||||
@@ -486,4 +504,4 @@ fn test_group_edge_cases() {
|
||||
assert retrieved_large.administrators[0] == 1000
|
||||
assert retrieved_large.administrators[99] == 1099
|
||||
assert retrieved_large.config.max_members == 99999
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,17 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_member_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut member_db := DBMember{db: &mydb}
|
||||
mut member_db := DBMember{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut member := member_db.new(
|
||||
name: 'Test Member'
|
||||
name: 'Test Member'
|
||||
description: 'A test member for unit testing'
|
||||
group_id: 1
|
||||
user_id: 10
|
||||
role: .admin
|
||||
status: .active
|
||||
group_id: 1
|
||||
user_id: 10
|
||||
role: .admin
|
||||
status: .active
|
||||
)!
|
||||
|
||||
assert member.name == 'Test Member'
|
||||
@@ -32,24 +34,26 @@ fn test_member_new() {
|
||||
|
||||
fn test_member_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut member_db := DBMember{db: &mydb}
|
||||
mut member_db := DBMember{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut original_member := member_db.new(
|
||||
name: 'Encoding Test Member'
|
||||
name: 'Encoding Test Member'
|
||||
description: 'Testing encoding and decoding'
|
||||
group_id: 999
|
||||
user_id: 888
|
||||
role: .moderator
|
||||
status: .suspended
|
||||
group_id: 999
|
||||
user_id: 888
|
||||
role: .moderator
|
||||
status: .suspended
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_member.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_member := Member{}
|
||||
member_db.load(mut decoded_member, mut decoder_obj)!
|
||||
|
||||
@@ -64,16 +68,18 @@ fn test_member_encoding_decoding() {
|
||||
|
||||
fn test_member_crud_operations() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut member_db := DBMember{db: &mydb}
|
||||
mut member_db := DBMember{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save
|
||||
mut member := member_db.new(
|
||||
name: 'CRUD Test Member'
|
||||
name: 'CRUD Test Member'
|
||||
description: 'Testing CRUD operations'
|
||||
group_id: 5
|
||||
user_id: 15
|
||||
role: .member
|
||||
status: .pending
|
||||
group_id: 5
|
||||
user_id: 15
|
||||
role: .member
|
||||
status: .pending
|
||||
)!
|
||||
|
||||
member = member_db.set(member)!
|
||||
@@ -108,28 +114,30 @@ fn test_member_crud_operations() {
|
||||
|
||||
fn test_member_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut member_db := DBMember{db: &mydb}
|
||||
mut member_db := DBMember{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
initial_list := member_db.list()!
|
||||
initial_count := initial_list.len
|
||||
|
||||
// Create multiple members
|
||||
mut member1 := member_db.new(
|
||||
name: 'Member 1'
|
||||
name: 'Member 1'
|
||||
description: 'First member'
|
||||
group_id: 1
|
||||
user_id: 1
|
||||
role: .admin
|
||||
status: .active
|
||||
group_id: 1
|
||||
user_id: 1
|
||||
role: .admin
|
||||
status: .active
|
||||
)!
|
||||
|
||||
mut member2 := member_db.new(
|
||||
name: 'Member 2'
|
||||
name: 'Member 2'
|
||||
description: 'Second member'
|
||||
group_id: 2
|
||||
user_id: 2
|
||||
role: .member
|
||||
status: .pending
|
||||
group_id: 2
|
||||
user_id: 2
|
||||
role: .member
|
||||
status: .pending
|
||||
)!
|
||||
|
||||
member1 = member_db.set(member1)!
|
||||
@@ -155,7 +163,9 @@ fn test_member_list() {
|
||||
|
||||
fn test_member_roles_and_statuses() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut member_db := DBMember{db: &mydb}
|
||||
mut member_db := DBMember{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
roles := [MemberRole.member, .moderator, .admin, .owner]
|
||||
statuses := [MemberStatus.pending, .active, .suspended, .archived]
|
||||
@@ -163,12 +173,12 @@ fn test_member_roles_and_statuses() {
|
||||
for i, role in roles {
|
||||
status := statuses[i % statuses.len]
|
||||
mut member := member_db.new(
|
||||
name: 'Role Test ${i}'
|
||||
name: 'Role Test ${i}'
|
||||
description: 'Testing ${role} with ${status}'
|
||||
group_id: u32(i + 1)
|
||||
user_id: u32(i + 100)
|
||||
role: role
|
||||
status: status
|
||||
group_id: u32(i + 1)
|
||||
user_id: u32(i + 100)
|
||||
role: role
|
||||
status: status
|
||||
)!
|
||||
|
||||
member = member_db.set(member)!
|
||||
@@ -176,4 +186,4 @@ fn test_member_roles_and_statuses() {
|
||||
assert retrieved.role == role
|
||||
assert retrieved.status == status
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,17 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_notary_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut notary_db := DBNotary{db: &mydb}
|
||||
mut notary_db := DBNotary{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut notary := notary_db.new(
|
||||
name: 'Test Notary'
|
||||
name: 'Test Notary'
|
||||
description: 'A test notary for unit testing'
|
||||
notary_id: 1
|
||||
pubkey: 'ed25519_ABCD1234567890EFGH'
|
||||
address: 'TFT_ADDRESS_XYZ123'
|
||||
is_active: true
|
||||
notary_id: 1
|
||||
pubkey: 'ed25519_ABCD1234567890EFGH'
|
||||
address: 'TFT_ADDRESS_XYZ123'
|
||||
is_active: true
|
||||
)!
|
||||
|
||||
assert notary.name == 'Test Notary'
|
||||
@@ -30,24 +32,26 @@ fn test_notary_new() {
|
||||
|
||||
fn test_notary_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut notary_db := DBNotary{db: &mydb}
|
||||
mut notary_db := DBNotary{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut original_notary := notary_db.new(
|
||||
name: 'Encoding Test Notary'
|
||||
name: 'Encoding Test Notary'
|
||||
description: 'Testing encoding and decoding'
|
||||
notary_id: 999
|
||||
pubkey: 'ed25519_ENCODING_TEST_PUBKEY_123456789'
|
||||
address: 'TFT_ENCODING_ADDRESS_ABCDEF'
|
||||
is_active: false
|
||||
notary_id: 999
|
||||
pubkey: 'ed25519_ENCODING_TEST_PUBKEY_123456789'
|
||||
address: 'TFT_ENCODING_ADDRESS_ABCDEF'
|
||||
is_active: false
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_notary.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_notary := Notary{}
|
||||
notary_db.load(mut decoded_notary, mut decoder_obj)!
|
||||
|
||||
@@ -60,16 +64,18 @@ fn test_notary_encoding_decoding() {
|
||||
|
||||
fn test_notary_crud_operations() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut notary_db := DBNotary{db: &mydb}
|
||||
mut notary_db := DBNotary{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save
|
||||
mut notary := notary_db.new(
|
||||
name: 'CRUD Test Notary'
|
||||
name: 'CRUD Test Notary'
|
||||
description: 'Testing CRUD operations'
|
||||
notary_id: 5
|
||||
pubkey: 'ed25519_CRUD_TEST_PUBKEY'
|
||||
address: 'TFT_CRUD_ADDRESS'
|
||||
is_active: true
|
||||
notary_id: 5
|
||||
pubkey: 'ed25519_CRUD_TEST_PUBKEY'
|
||||
address: 'TFT_CRUD_ADDRESS'
|
||||
is_active: true
|
||||
)!
|
||||
|
||||
notary = notary_db.set(notary)!
|
||||
@@ -104,28 +110,30 @@ fn test_notary_crud_operations() {
|
||||
|
||||
fn test_notary_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut notary_db := DBNotary{db: &mydb}
|
||||
mut notary_db := DBNotary{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
initial_list := notary_db.list()!
|
||||
initial_count := initial_list.len
|
||||
|
||||
// Create multiple notaries
|
||||
mut notary1 := notary_db.new(
|
||||
name: 'Notary 1'
|
||||
name: 'Notary 1'
|
||||
description: 'First notary'
|
||||
notary_id: 1
|
||||
pubkey: 'ed25519_NOTARY1_PUBKEY'
|
||||
address: 'TFT_NOTARY1_ADDRESS'
|
||||
is_active: true
|
||||
notary_id: 1
|
||||
pubkey: 'ed25519_NOTARY1_PUBKEY'
|
||||
address: 'TFT_NOTARY1_ADDRESS'
|
||||
is_active: true
|
||||
)!
|
||||
|
||||
mut notary2 := notary_db.new(
|
||||
name: 'Notary 2'
|
||||
name: 'Notary 2'
|
||||
description: 'Second notary'
|
||||
notary_id: 2
|
||||
pubkey: 'ed25519_NOTARY2_PUBKEY'
|
||||
address: 'TFT_NOTARY2_ADDRESS'
|
||||
is_active: false
|
||||
notary_id: 2
|
||||
pubkey: 'ed25519_NOTARY2_PUBKEY'
|
||||
address: 'TFT_NOTARY2_ADDRESS'
|
||||
is_active: false
|
||||
)!
|
||||
|
||||
notary1 = notary_db.set(notary1)!
|
||||
@@ -151,16 +159,18 @@ fn test_notary_list() {
|
||||
|
||||
fn test_notary_edge_cases() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut notary_db := DBNotary{db: &mydb}
|
||||
mut notary_db := DBNotary{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test empty strings
|
||||
mut minimal_notary := notary_db.new(
|
||||
name: ''
|
||||
name: ''
|
||||
description: ''
|
||||
notary_id: 0
|
||||
pubkey: ''
|
||||
address: ''
|
||||
is_active: false
|
||||
notary_id: 0
|
||||
pubkey: ''
|
||||
address: ''
|
||||
is_active: false
|
||||
)!
|
||||
|
||||
minimal_notary = notary_db.set(minimal_notary)!
|
||||
@@ -178,12 +188,12 @@ fn test_notary_edge_cases() {
|
||||
long_address := 'TFT_' + 'B'.repeat(1000)
|
||||
|
||||
mut long_notary := notary_db.new(
|
||||
name: 'Long String Notary'
|
||||
name: 'Long String Notary'
|
||||
description: 'Testing with very long strings'
|
||||
notary_id: 999999
|
||||
pubkey: long_pubkey
|
||||
address: long_address
|
||||
is_active: true
|
||||
notary_id: 999999
|
||||
pubkey: long_pubkey
|
||||
address: long_address
|
||||
is_active: true
|
||||
)!
|
||||
|
||||
long_notary = notary_db.set(long_notary)!
|
||||
@@ -192,4 +202,4 @@ fn test_notary_edge_cases() {
|
||||
assert retrieved_long.pubkey == long_pubkey
|
||||
assert retrieved_long.address == long_address
|
||||
assert retrieved_long.notary_id == 999999
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_signature_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut sig_db := DBSignature{db: &mydb}
|
||||
mut sig_db := DBSignature{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut signature := sig_db.new(
|
||||
name: 'Test Signature'
|
||||
name: 'Test Signature'
|
||||
description: 'A test signature for unit testing'
|
||||
signer_id: 1
|
||||
tx_id: 123
|
||||
signature: 'abcd1234567890efgh'
|
||||
signer_id: 1
|
||||
tx_id: 123
|
||||
signature: 'abcd1234567890efgh'
|
||||
)!
|
||||
|
||||
assert signature.name == 'Test Signature'
|
||||
@@ -29,23 +31,25 @@ fn test_signature_new() {
|
||||
|
||||
fn test_signature_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut sig_db := DBSignature{db: &mydb}
|
||||
mut sig_db := DBSignature{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut original_sig := sig_db.new(
|
||||
name: 'Encoding Test Signature'
|
||||
name: 'Encoding Test Signature'
|
||||
description: 'Testing encoding and decoding'
|
||||
signer_id: 999
|
||||
tx_id: 888
|
||||
signature: 'hex_encoded_signature_123456789abcdef'
|
||||
signer_id: 999
|
||||
tx_id: 888
|
||||
signature: 'hex_encoded_signature_123456789abcdef'
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_sig.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_sig := Signature{}
|
||||
sig_db.load(mut decoded_sig, mut decoder_obj)!
|
||||
|
||||
@@ -58,15 +62,17 @@ fn test_signature_encoding_decoding() {
|
||||
|
||||
fn test_signature_crud_operations() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut sig_db := DBSignature{db: &mydb}
|
||||
mut sig_db := DBSignature{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save
|
||||
mut signature := sig_db.new(
|
||||
name: 'CRUD Test Signature'
|
||||
name: 'CRUD Test Signature'
|
||||
description: 'Testing CRUD operations'
|
||||
signer_id: 5
|
||||
tx_id: 15
|
||||
signature: 'crud_test_signature_hex'
|
||||
signer_id: 5
|
||||
tx_id: 15
|
||||
signature: 'crud_test_signature_hex'
|
||||
)!
|
||||
|
||||
signature = sig_db.set(signature)!
|
||||
@@ -98,26 +104,28 @@ fn test_signature_crud_operations() {
|
||||
|
||||
fn test_signature_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut sig_db := DBSignature{db: &mydb}
|
||||
mut sig_db := DBSignature{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
initial_list := sig_db.list()!
|
||||
initial_count := initial_list.len
|
||||
|
||||
// Create multiple signatures
|
||||
mut sig1 := sig_db.new(
|
||||
name: 'Signature 1'
|
||||
name: 'Signature 1'
|
||||
description: 'First signature'
|
||||
signer_id: 1
|
||||
tx_id: 101
|
||||
signature: 'signature1_hex'
|
||||
signer_id: 1
|
||||
tx_id: 101
|
||||
signature: 'signature1_hex'
|
||||
)!
|
||||
|
||||
mut sig2 := sig_db.new(
|
||||
name: 'Signature 2'
|
||||
name: 'Signature 2'
|
||||
description: 'Second signature'
|
||||
signer_id: 2
|
||||
tx_id: 102
|
||||
signature: 'signature2_hex'
|
||||
signer_id: 2
|
||||
tx_id: 102
|
||||
signature: 'signature2_hex'
|
||||
)!
|
||||
|
||||
sig1 = sig_db.set(sig1)!
|
||||
@@ -143,15 +151,17 @@ fn test_signature_list() {
|
||||
|
||||
fn test_signature_edge_cases() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut sig_db := DBSignature{db: &mydb}
|
||||
mut sig_db := DBSignature{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test minimal signature
|
||||
mut minimal_sig := sig_db.new(
|
||||
name: ''
|
||||
name: ''
|
||||
description: ''
|
||||
signer_id: 0
|
||||
tx_id: 0
|
||||
signature: ''
|
||||
signer_id: 0
|
||||
tx_id: 0
|
||||
signature: ''
|
||||
)!
|
||||
|
||||
minimal_sig = sig_db.set(minimal_sig)!
|
||||
@@ -167,11 +177,11 @@ fn test_signature_edge_cases() {
|
||||
long_signature := 'A'.repeat(10000)
|
||||
|
||||
mut long_sig := sig_db.new(
|
||||
name: 'Long Signature'
|
||||
name: 'Long Signature'
|
||||
description: 'Testing with very long signature'
|
||||
signer_id: 999999
|
||||
tx_id: 888888
|
||||
signature: long_signature
|
||||
signer_id: 999999
|
||||
tx_id: 888888
|
||||
signature: long_signature
|
||||
)!
|
||||
|
||||
long_sig = sig_db.set(long_sig)!
|
||||
@@ -180,4 +190,4 @@ fn test_signature_edge_cases() {
|
||||
assert retrieved_long.signature == long_signature
|
||||
assert retrieved_long.signer_id == 999999
|
||||
assert retrieved_long.tx_id == 888888
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@ module models_ledger
|
||||
import freeflowuniverse.herolib.hero.db
|
||||
|
||||
fn setup_test_db() !db.DB {
|
||||
return db.new(namespace: ':memory:')!
|
||||
}
|
||||
mut mydb := db.new()!
|
||||
return mydb
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_transaction_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create test transaction with signatures
|
||||
sig1 := TransactionSignature{
|
||||
@@ -23,18 +25,18 @@ fn test_transaction_new() {
|
||||
}
|
||||
|
||||
mut transaction := tx_db.new(
|
||||
name: 'Test Transaction'
|
||||
name: 'Test Transaction'
|
||||
description: 'A test transaction for unit testing'
|
||||
txid: 12345
|
||||
source: 100
|
||||
txid: 12345
|
||||
source: 100
|
||||
destination: 200
|
||||
assetid: 1
|
||||
amount: 500.75
|
||||
timestamp: 1234567890
|
||||
status: 'pending'
|
||||
memo: 'Test transfer'
|
||||
tx_type: .transfer
|
||||
signatures: [sig1, sig2]
|
||||
assetid: 1
|
||||
amount: 500.75
|
||||
timestamp: 1234567890
|
||||
status: 'pending'
|
||||
memo: 'Test transfer'
|
||||
tx_type: .transfer
|
||||
signatures: [sig1, sig2]
|
||||
)!
|
||||
|
||||
// Verify the transaction was created with correct values
|
||||
@@ -58,7 +60,9 @@ fn test_transaction_new() {
|
||||
|
||||
fn test_transaction_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create a complex transaction with multiple signatures
|
||||
sigs := [
|
||||
@@ -76,31 +80,31 @@ fn test_transaction_encoding_decoding() {
|
||||
signer_id: 30
|
||||
signature: 'complex_sig_3_mnopqr345678'
|
||||
timestamp: 1234567802
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
mut original_tx := tx_db.new(
|
||||
name: 'Encoding Test Transaction'
|
||||
name: 'Encoding Test Transaction'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
txid: 99999
|
||||
source: 999
|
||||
txid: 99999
|
||||
source: 999
|
||||
destination: 888
|
||||
assetid: 5
|
||||
amount: 12345.6789
|
||||
timestamp: 1234567890
|
||||
status: 'completed'
|
||||
memo: 'Complex transaction for encoding test with special chars: !@#$%^&*()'
|
||||
tx_type: .clawback
|
||||
signatures: sigs
|
||||
assetid: 5
|
||||
amount: 12345.6789
|
||||
timestamp: 1234567890
|
||||
status: 'completed'
|
||||
memo: 'Complex transaction for encoding test with special chars: !@#$%^&*()'
|
||||
tx_type: .clawback
|
||||
signatures: sigs
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_tx.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_tx := Transaction{}
|
||||
tx_db.load(mut decoded_tx, mut decoder_obj)!
|
||||
|
||||
@@ -126,7 +130,9 @@ fn test_transaction_encoding_decoding() {
|
||||
|
||||
fn test_transaction_set_and_get() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create transaction
|
||||
sig := TransactionSignature{
|
||||
@@ -136,18 +142,18 @@ fn test_transaction_set_and_get() {
|
||||
}
|
||||
|
||||
mut transaction := tx_db.new(
|
||||
name: 'DB Test Transaction'
|
||||
name: 'DB Test Transaction'
|
||||
description: 'Testing database operations'
|
||||
txid: 555
|
||||
source: 111
|
||||
txid: 555
|
||||
source: 111
|
||||
destination: 222
|
||||
assetid: 3
|
||||
amount: 100.50
|
||||
timestamp: 1234567890
|
||||
status: 'confirmed'
|
||||
memo: 'Database test transfer'
|
||||
tx_type: .transfer
|
||||
signatures: [sig]
|
||||
assetid: 3
|
||||
amount: 100.50
|
||||
timestamp: 1234567890
|
||||
status: 'confirmed'
|
||||
memo: 'Database test transfer'
|
||||
tx_type: .transfer
|
||||
signatures: [sig]
|
||||
)!
|
||||
|
||||
// Save the transaction
|
||||
@@ -180,22 +186,24 @@ fn test_transaction_set_and_get() {
|
||||
|
||||
fn test_transaction_update() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save a transaction
|
||||
mut transaction := tx_db.new(
|
||||
name: 'Original Transaction'
|
||||
name: 'Original Transaction'
|
||||
description: 'Original description'
|
||||
txid: 777
|
||||
source: 100
|
||||
txid: 777
|
||||
source: 100
|
||||
destination: 200
|
||||
assetid: 1
|
||||
amount: 50.0
|
||||
timestamp: 1234567890
|
||||
status: 'pending'
|
||||
memo: 'Original memo'
|
||||
tx_type: .transfer
|
||||
signatures: []TransactionSignature{}
|
||||
assetid: 1
|
||||
amount: 50.0
|
||||
timestamp: 1234567890
|
||||
status: 'pending'
|
||||
memo: 'Original memo'
|
||||
tx_type: .transfer
|
||||
signatures: []TransactionSignature{}
|
||||
)!
|
||||
|
||||
transaction = tx_db.set(transaction)!
|
||||
@@ -235,7 +243,9 @@ fn test_transaction_update() {
|
||||
|
||||
fn test_transaction_exist_and_delete() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test non-existent transaction
|
||||
exists := tx_db.exist(999)!
|
||||
@@ -243,18 +253,18 @@ fn test_transaction_exist_and_delete() {
|
||||
|
||||
// Create and save a transaction
|
||||
mut transaction := tx_db.new(
|
||||
name: 'To Be Deleted'
|
||||
name: 'To Be Deleted'
|
||||
description: 'This transaction will be deleted'
|
||||
txid: 666
|
||||
source: 100
|
||||
txid: 666
|
||||
source: 100
|
||||
destination: 200
|
||||
assetid: 1
|
||||
amount: 1.0
|
||||
timestamp: 1234567890
|
||||
status: 'failed'
|
||||
memo: 'Delete me'
|
||||
tx_type: .burn
|
||||
signatures: []TransactionSignature{}
|
||||
assetid: 1
|
||||
amount: 1.0
|
||||
timestamp: 1234567890
|
||||
status: 'failed'
|
||||
memo: 'Delete me'
|
||||
tx_type: .burn
|
||||
signatures: []TransactionSignature{}
|
||||
)!
|
||||
|
||||
transaction = tx_db.set(transaction)!
|
||||
@@ -279,7 +289,9 @@ fn test_transaction_exist_and_delete() {
|
||||
|
||||
fn test_transaction_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Initially should be empty
|
||||
initial_list := tx_db.list()!
|
||||
@@ -287,33 +299,33 @@ fn test_transaction_list() {
|
||||
|
||||
// Create multiple transactions
|
||||
mut tx1 := tx_db.new(
|
||||
name: 'Transaction 1'
|
||||
name: 'Transaction 1'
|
||||
description: 'First transaction'
|
||||
txid: 1001
|
||||
source: 1
|
||||
txid: 1001
|
||||
source: 1
|
||||
destination: 2
|
||||
assetid: 1
|
||||
amount: 100.0
|
||||
timestamp: 1234567890
|
||||
status: 'completed'
|
||||
memo: 'First'
|
||||
tx_type: .transfer
|
||||
signatures: []TransactionSignature{}
|
||||
assetid: 1
|
||||
amount: 100.0
|
||||
timestamp: 1234567890
|
||||
status: 'completed'
|
||||
memo: 'First'
|
||||
tx_type: .transfer
|
||||
signatures: []TransactionSignature{}
|
||||
)!
|
||||
|
||||
mut tx2 := tx_db.new(
|
||||
name: 'Transaction 2'
|
||||
name: 'Transaction 2'
|
||||
description: 'Second transaction'
|
||||
txid: 1002
|
||||
source: 2
|
||||
txid: 1002
|
||||
source: 2
|
||||
destination: 3
|
||||
assetid: 2
|
||||
amount: 200.0
|
||||
timestamp: 1234567891
|
||||
status: 'pending'
|
||||
memo: 'Second'
|
||||
tx_type: .freeze
|
||||
signatures: []TransactionSignature{}
|
||||
assetid: 2
|
||||
amount: 200.0
|
||||
timestamp: 1234567891
|
||||
status: 'pending'
|
||||
memo: 'Second'
|
||||
tx_type: .freeze
|
||||
signatures: []TransactionSignature{}
|
||||
)!
|
||||
|
||||
// Save both transactions
|
||||
@@ -349,25 +361,27 @@ fn test_transaction_list() {
|
||||
|
||||
fn test_transaction_types() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test all transaction types
|
||||
tx_types := [TransactionType.transfer, .clawback, .freeze, .unfreeze, .issue, .burn]
|
||||
|
||||
for i, tx_type in tx_types {
|
||||
mut tx := tx_db.new(
|
||||
name: 'Transaction Type Test ${i}'
|
||||
name: 'Transaction Type Test ${i}'
|
||||
description: 'Testing ${tx_type}'
|
||||
txid: u32(2000 + i)
|
||||
source: 100
|
||||
txid: u32(2000 + i)
|
||||
source: 100
|
||||
destination: 200
|
||||
assetid: 1
|
||||
amount: f64(i + 1) * 10.0
|
||||
timestamp: 1234567890
|
||||
status: 'completed'
|
||||
memo: 'Type test for ${tx_type}'
|
||||
tx_type: tx_type
|
||||
signatures: []TransactionSignature{}
|
||||
assetid: 1
|
||||
amount: f64(i + 1) * 10.0
|
||||
timestamp: 1234567890
|
||||
status: 'completed'
|
||||
memo: 'Type test for ${tx_type}'
|
||||
tx_type: tx_type
|
||||
signatures: []TransactionSignature{}
|
||||
)!
|
||||
|
||||
tx = tx_db.set(tx)!
|
||||
@@ -378,22 +392,24 @@ fn test_transaction_types() {
|
||||
|
||||
fn test_transaction_edge_cases() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut tx_db := DBTransaction{db: &mydb}
|
||||
mut tx_db := DBTransaction{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test minimal transaction
|
||||
mut minimal_tx := tx_db.new(
|
||||
name: ''
|
||||
name: ''
|
||||
description: ''
|
||||
txid: 0
|
||||
source: 0
|
||||
txid: 0
|
||||
source: 0
|
||||
destination: 0
|
||||
assetid: 0
|
||||
amount: 0.0
|
||||
timestamp: 0
|
||||
status: ''
|
||||
memo: ''
|
||||
tx_type: .transfer
|
||||
signatures: []TransactionSignature{}
|
||||
assetid: 0
|
||||
amount: 0.0
|
||||
timestamp: 0
|
||||
status: ''
|
||||
memo: ''
|
||||
tx_type: .transfer
|
||||
signatures: []TransactionSignature{}
|
||||
)!
|
||||
|
||||
minimal_tx = tx_db.set(minimal_tx)!
|
||||
@@ -415,18 +431,18 @@ fn test_transaction_edge_cases() {
|
||||
}}
|
||||
|
||||
mut large_tx := tx_db.new(
|
||||
name: 'Large Signature Transaction'
|
||||
name: 'Large Signature Transaction'
|
||||
description: 'Transaction with many signatures'
|
||||
txid: 9999
|
||||
source: 100
|
||||
txid: 9999
|
||||
source: 100
|
||||
destination: 200
|
||||
assetid: 1
|
||||
amount: 1000.0
|
||||
timestamp: 1234567890
|
||||
status: 'multisig'
|
||||
memo: 'Many signatures test'
|
||||
tx_type: .transfer
|
||||
signatures: many_sigs
|
||||
assetid: 1
|
||||
amount: 1000.0
|
||||
timestamp: 1234567890
|
||||
status: 'multisig'
|
||||
memo: 'Many signatures test'
|
||||
tx_type: .transfer
|
||||
signatures: many_sigs
|
||||
)!
|
||||
|
||||
large_tx = tx_db.set(large_tx)!
|
||||
@@ -436,4 +452,4 @@ fn test_transaction_edge_cases() {
|
||||
assert retrieved_large.signatures[0].signer_id == 1
|
||||
assert retrieved_large.signatures[99].signer_id == 100
|
||||
assert retrieved_large.signatures[50].signature == 'sig_50_abcd123'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,28 +7,30 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_user_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut user_db := DBUser{db: &mydb}
|
||||
mut user_db := DBUser{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create test user with encrypted data
|
||||
secret_profile := SecretBox{
|
||||
data: [u8(1), 2, 3, 4, 5]
|
||||
data: [u8(1), 2, 3, 4, 5]
|
||||
nonce: [u8(10), 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
|
||||
}
|
||||
|
||||
secret_kyc := SecretBox{
|
||||
data: [u8(100), 101, 102, 103]
|
||||
data: [u8(100), 101, 102, 103]
|
||||
nonce: [u8(200), 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211]
|
||||
}
|
||||
|
||||
mut user := user_db.new(
|
||||
name: 'Test User'
|
||||
name: 'Test User'
|
||||
description: 'A test user for unit testing'
|
||||
username: 'testuser123'
|
||||
pubkey: 'ed25519_ABCD...XYZ'
|
||||
email: ['test@example.com', 'test2@example.com']
|
||||
status: .active
|
||||
username: 'testuser123'
|
||||
pubkey: 'ed25519_ABCD...XYZ'
|
||||
email: ['test@example.com', 'test2@example.com']
|
||||
status: .active
|
||||
userprofile: [secret_profile]
|
||||
kyc: [secret_kyc]
|
||||
kyc: [secret_kyc]
|
||||
)!
|
||||
|
||||
// Verify the user was created with correct values
|
||||
@@ -48,42 +50,44 @@ fn test_user_new() {
|
||||
|
||||
fn test_user_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut user_db := DBUser{db: &mydb}
|
||||
mut user_db := DBUser{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create a complex user with multiple encrypted boxes
|
||||
profile1 := SecretBox{
|
||||
data: [u8(1), 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
data: [u8(1), 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
nonce: [u8(10), 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
|
||||
}
|
||||
|
||||
profile2 := SecretBox{
|
||||
data: [u8(50), 51, 52, 53, 54]
|
||||
data: [u8(50), 51, 52, 53, 54]
|
||||
nonce: [u8(60), 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71]
|
||||
}
|
||||
|
||||
kyc1 := SecretBox{
|
||||
data: [u8(100), 101, 102, 103, 104, 105, 106]
|
||||
data: [u8(100), 101, 102, 103, 104, 105, 106]
|
||||
nonce: [u8(200), 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211]
|
||||
}
|
||||
|
||||
mut original_user := user_db.new(
|
||||
name: 'Encoding Test User'
|
||||
name: 'Encoding Test User'
|
||||
description: 'Testing encoding and decoding functionality'
|
||||
username: 'encodeuser'
|
||||
pubkey: 'ed25519_ENCODE...TEST'
|
||||
email: ['encode@test.com', 'encode2@test.com', 'encode3@test.com']
|
||||
status: .suspended
|
||||
username: 'encodeuser'
|
||||
pubkey: 'ed25519_ENCODE...TEST'
|
||||
email: ['encode@test.com', 'encode2@test.com', 'encode3@test.com']
|
||||
status: .suspended
|
||||
userprofile: [profile1, profile2]
|
||||
kyc: [kyc1]
|
||||
kyc: [kyc1]
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_user.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_user := User{}
|
||||
user_db.load(mut decoded_user, mut decoder_obj)!
|
||||
|
||||
@@ -127,18 +131,20 @@ fn test_user_encoding_decoding() {
|
||||
|
||||
fn test_user_set_and_get() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut user_db := DBUser{db: &mydb}
|
||||
mut user_db := DBUser{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create user
|
||||
mut user := user_db.new(
|
||||
name: 'DB Test User'
|
||||
name: 'DB Test User'
|
||||
description: 'Testing database operations'
|
||||
username: 'dbuser'
|
||||
pubkey: 'ed25519_DB...TEST'
|
||||
email: ['db@test.com']
|
||||
status: .active
|
||||
username: 'dbuser'
|
||||
pubkey: 'ed25519_DB...TEST'
|
||||
email: ['db@test.com']
|
||||
status: .active
|
||||
userprofile: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
)!
|
||||
|
||||
// Save the user
|
||||
@@ -166,18 +172,20 @@ fn test_user_set_and_get() {
|
||||
|
||||
fn test_user_update() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut user_db := DBUser{db: &mydb}
|
||||
mut user_db := DBUser{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save a user
|
||||
mut user := user_db.new(
|
||||
name: 'Original User'
|
||||
name: 'Original User'
|
||||
description: 'Original description'
|
||||
username: 'original'
|
||||
pubkey: 'ed25519_ORIG...123'
|
||||
email: ['orig@test.com']
|
||||
status: .active
|
||||
username: 'original'
|
||||
pubkey: 'ed25519_ORIG...123'
|
||||
email: ['orig@test.com']
|
||||
status: .active
|
||||
userprofile: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
)!
|
||||
|
||||
user = user_db.set(user)!
|
||||
@@ -186,7 +194,7 @@ fn test_user_update() {
|
||||
|
||||
// Update the user
|
||||
new_profile := SecretBox{
|
||||
data: [u8(99), 98, 97]
|
||||
data: [u8(99), 98, 97]
|
||||
nonce: [u8(10), 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
|
||||
}
|
||||
|
||||
@@ -216,7 +224,9 @@ fn test_user_update() {
|
||||
|
||||
fn test_user_exist_and_delete() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut user_db := DBUser{db: &mydb}
|
||||
mut user_db := DBUser{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test non-existent user
|
||||
exists := user_db.exist(999)!
|
||||
@@ -224,14 +234,14 @@ fn test_user_exist_and_delete() {
|
||||
|
||||
// Create and save a user
|
||||
mut user := user_db.new(
|
||||
name: 'To Be Deleted'
|
||||
name: 'To Be Deleted'
|
||||
description: 'This user will be deleted'
|
||||
username: 'deleteme'
|
||||
pubkey: 'ed25519_DEL...123'
|
||||
email: ['delete@test.com']
|
||||
status: .archived
|
||||
username: 'deleteme'
|
||||
pubkey: 'ed25519_DEL...123'
|
||||
email: ['delete@test.com']
|
||||
status: .archived
|
||||
userprofile: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
)!
|
||||
|
||||
user = user_db.set(user)!
|
||||
@@ -256,7 +266,9 @@ fn test_user_exist_and_delete() {
|
||||
|
||||
fn test_user_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut user_db := DBUser{db: &mydb}
|
||||
mut user_db := DBUser{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Initially should be empty
|
||||
initial_list := user_db.list()!
|
||||
@@ -264,25 +276,25 @@ fn test_user_list() {
|
||||
|
||||
// Create multiple users
|
||||
mut user1 := user_db.new(
|
||||
name: 'User 1'
|
||||
name: 'User 1'
|
||||
description: 'First user'
|
||||
username: 'user1'
|
||||
pubkey: 'ed25519_USER1...123'
|
||||
email: ['user1@test.com']
|
||||
status: .active
|
||||
username: 'user1'
|
||||
pubkey: 'ed25519_USER1...123'
|
||||
email: ['user1@test.com']
|
||||
status: .active
|
||||
userprofile: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
)!
|
||||
|
||||
mut user2 := user_db.new(
|
||||
name: 'User 2'
|
||||
name: 'User 2'
|
||||
description: 'Second user'
|
||||
username: 'user2'
|
||||
pubkey: 'ed25519_USER2...456'
|
||||
email: ['user2@test.com', 'user2alt@test.com']
|
||||
status: .suspended
|
||||
username: 'user2'
|
||||
pubkey: 'ed25519_USER2...456'
|
||||
email: ['user2@test.com', 'user2alt@test.com']
|
||||
status: .suspended
|
||||
userprofile: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
)!
|
||||
|
||||
// Save both users
|
||||
@@ -318,18 +330,20 @@ fn test_user_list() {
|
||||
|
||||
fn test_user_edge_cases() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut user_db := DBUser{db: &mydb}
|
||||
mut user_db := DBUser{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test empty/minimal user
|
||||
mut minimal_user := user_db.new(
|
||||
name: ''
|
||||
name: ''
|
||||
description: ''
|
||||
username: ''
|
||||
pubkey: ''
|
||||
email: []string{}
|
||||
status: .active
|
||||
username: ''
|
||||
pubkey: ''
|
||||
email: []string{}
|
||||
status: .active
|
||||
userprofile: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
kyc: []SecretBox{}
|
||||
)!
|
||||
|
||||
minimal_user = user_db.set(minimal_user)!
|
||||
@@ -348,19 +362,19 @@ fn test_user_edge_cases() {
|
||||
large_nonce := []u8{len: 12, init: u8(index + 100)}
|
||||
|
||||
large_secret := SecretBox{
|
||||
data: large_data
|
||||
data: large_data
|
||||
nonce: large_nonce
|
||||
}
|
||||
|
||||
mut large_user := user_db.new(
|
||||
name: 'Large Data User'
|
||||
name: 'Large Data User'
|
||||
description: 'User with large encrypted data'
|
||||
username: 'largeuser'
|
||||
pubkey: 'ed25519_LARGE...123'
|
||||
email: ['large@test.com']
|
||||
status: .active
|
||||
username: 'largeuser'
|
||||
pubkey: 'ed25519_LARGE...123'
|
||||
email: ['large@test.com']
|
||||
status: .active
|
||||
userprofile: [large_secret, large_secret] // Duplicate for testing
|
||||
kyc: [large_secret]
|
||||
kyc: [large_secret]
|
||||
)!
|
||||
|
||||
large_user = user_db.set(large_user)!
|
||||
@@ -372,4 +386,4 @@ fn test_user_edge_cases() {
|
||||
assert retrieved_large.userprofile[0].nonce.len == 12
|
||||
assert retrieved_large.userprofile[0].data[0] == 0
|
||||
assert retrieved_large.userprofile[0].data[999] == 231 // 999 % 256
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_userkvs_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut kvs_db := DBUserKVS{db: &mydb}
|
||||
mut kvs_db := DBUserKVS{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut userkvs := kvs_db.new(
|
||||
name: 'Test User KVS'
|
||||
name: 'Test User KVS'
|
||||
description: 'A test user KVS for unit testing'
|
||||
user_id: 1
|
||||
user_id: 1
|
||||
)!
|
||||
|
||||
assert userkvs.name == 'Test User KVS'
|
||||
@@ -24,21 +26,23 @@ fn test_userkvs_new() {
|
||||
|
||||
fn test_userkvs_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut kvs_db := DBUserKVS{db: &mydb}
|
||||
mut kvs_db := DBUserKVS{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut original_kvs := kvs_db.new(
|
||||
name: 'Encoding Test KVS'
|
||||
name: 'Encoding Test KVS'
|
||||
description: 'Testing encoding and decoding'
|
||||
user_id: 999
|
||||
user_id: 999
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_kvs.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_kvs := UserKVS{}
|
||||
kvs_db.load(mut decoded_kvs, mut decoder_obj)!
|
||||
|
||||
@@ -48,13 +52,15 @@ fn test_userkvs_encoding_decoding() {
|
||||
|
||||
fn test_userkvs_crud_operations() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut kvs_db := DBUserKVS{db: &mydb}
|
||||
mut kvs_db := DBUserKVS{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save
|
||||
mut userkvs := kvs_db.new(
|
||||
name: 'CRUD Test KVS'
|
||||
name: 'CRUD Test KVS'
|
||||
description: 'Testing CRUD operations'
|
||||
user_id: 5
|
||||
user_id: 5
|
||||
)!
|
||||
|
||||
userkvs = kvs_db.set(userkvs)!
|
||||
@@ -87,22 +93,24 @@ fn test_userkvs_crud_operations() {
|
||||
|
||||
fn test_userkvs_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut kvs_db := DBUserKVS{db: &mydb}
|
||||
mut kvs_db := DBUserKVS{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
initial_list := kvs_db.list()!
|
||||
initial_count := initial_list.len
|
||||
|
||||
// Create multiple KVS
|
||||
mut kvs1 := kvs_db.new(
|
||||
name: 'KVS 1'
|
||||
name: 'KVS 1'
|
||||
description: 'First KVS'
|
||||
user_id: 1
|
||||
user_id: 1
|
||||
)!
|
||||
|
||||
mut kvs2 := kvs_db.new(
|
||||
name: 'KVS 2'
|
||||
name: 'KVS 2'
|
||||
description: 'Second KVS'
|
||||
user_id: 2
|
||||
user_id: 2
|
||||
)!
|
||||
|
||||
kvs1 = kvs_db.set(kvs1)!
|
||||
@@ -124,4 +132,4 @@ fn test_userkvs_list() {
|
||||
}
|
||||
}
|
||||
assert found1 && found2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ import freeflowuniverse.herolib.data.encoder
|
||||
|
||||
fn test_userkvsitem_new() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut item_db := DBUserKVSItem{db: &mydb}
|
||||
mut item_db := DBUserKVSItem{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut item := item_db.new(
|
||||
name: 'Test KVS Item'
|
||||
name: 'Test KVS Item'
|
||||
description: 'A test KVS item for unit testing'
|
||||
kvs_id: 1
|
||||
key: 'test_key'
|
||||
value: 'test_value'
|
||||
kvs_id: 1
|
||||
key: 'test_key'
|
||||
value: 'test_value'
|
||||
)!
|
||||
|
||||
assert item.name == 'Test KVS Item'
|
||||
@@ -29,23 +31,25 @@ fn test_userkvsitem_new() {
|
||||
|
||||
fn test_userkvsitem_encoding_decoding() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut item_db := DBUserKVSItem{db: &mydb}
|
||||
mut item_db := DBUserKVSItem{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
mut original_item := item_db.new(
|
||||
name: 'Encoding Test Item'
|
||||
name: 'Encoding Test Item'
|
||||
description: 'Testing encoding and decoding'
|
||||
kvs_id: 999
|
||||
key: 'encoding_key'
|
||||
value: 'encoding_value_with_special_chars_!@#$%^&*()'
|
||||
kvs_id: 999
|
||||
key: 'encoding_key'
|
||||
value: 'encoding_value_with_special_chars_!@#$%^&*()'
|
||||
)!
|
||||
|
||||
// Test encoding
|
||||
mut encoder_obj := encoder.new()
|
||||
mut encoder_obj := encoder.encoder_new()
|
||||
original_item.dump(mut encoder_obj)!
|
||||
encoded_data := encoder_obj.bytes()
|
||||
encoded_data := encoder_obj.data
|
||||
|
||||
// Test decoding
|
||||
mut decoder_obj := encoder.new_decoder(encoded_data)
|
||||
mut decoder_obj := encoder.decoder_new(encoded_data)
|
||||
mut decoded_item := UserKVSItem{}
|
||||
item_db.load(mut decoded_item, mut decoder_obj)!
|
||||
|
||||
@@ -58,15 +62,17 @@ fn test_userkvsitem_encoding_decoding() {
|
||||
|
||||
fn test_userkvsitem_crud_operations() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut item_db := DBUserKVSItem{db: &mydb}
|
||||
mut item_db := DBUserKVSItem{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Create and save
|
||||
mut item := item_db.new(
|
||||
name: 'CRUD Test Item'
|
||||
name: 'CRUD Test Item'
|
||||
description: 'Testing CRUD operations'
|
||||
kvs_id: 5
|
||||
key: 'crud_key'
|
||||
value: 'crud_value'
|
||||
kvs_id: 5
|
||||
key: 'crud_key'
|
||||
value: 'crud_value'
|
||||
)!
|
||||
|
||||
item = item_db.set(item)!
|
||||
@@ -100,26 +106,28 @@ fn test_userkvsitem_crud_operations() {
|
||||
|
||||
fn test_userkvsitem_list() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut item_db := DBUserKVSItem{db: &mydb}
|
||||
mut item_db := DBUserKVSItem{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
initial_list := item_db.list()!
|
||||
initial_count := initial_list.len
|
||||
|
||||
// Create multiple items
|
||||
mut item1 := item_db.new(
|
||||
name: 'Item 1'
|
||||
name: 'Item 1'
|
||||
description: 'First item'
|
||||
kvs_id: 1
|
||||
key: 'key1'
|
||||
value: 'value1'
|
||||
kvs_id: 1
|
||||
key: 'key1'
|
||||
value: 'value1'
|
||||
)!
|
||||
|
||||
mut item2 := item_db.new(
|
||||
name: 'Item 2'
|
||||
name: 'Item 2'
|
||||
description: 'Second item'
|
||||
kvs_id: 2
|
||||
key: 'key2'
|
||||
value: 'value2'
|
||||
kvs_id: 2
|
||||
key: 'key2'
|
||||
value: 'value2'
|
||||
)!
|
||||
|
||||
item1 = item_db.set(item1)!
|
||||
@@ -147,15 +155,17 @@ fn test_userkvsitem_list() {
|
||||
|
||||
fn test_userkvsitem_edge_cases() {
|
||||
mut mydb := setup_test_db()!
|
||||
mut item_db := DBUserKVSItem{db: &mydb}
|
||||
mut item_db := DBUserKVSItem{
|
||||
db: &mydb
|
||||
}
|
||||
|
||||
// Test empty strings
|
||||
mut minimal_item := item_db.new(
|
||||
name: ''
|
||||
name: ''
|
||||
description: ''
|
||||
kvs_id: 0
|
||||
key: ''
|
||||
value: ''
|
||||
kvs_id: 0
|
||||
key: ''
|
||||
value: ''
|
||||
)!
|
||||
|
||||
minimal_item = item_db.set(minimal_item)!
|
||||
@@ -172,11 +182,11 @@ fn test_userkvsitem_edge_cases() {
|
||||
large_value := 'large_value_' + 'V'.repeat(10000)
|
||||
|
||||
mut large_item := item_db.new(
|
||||
name: 'Large Item'
|
||||
name: 'Large Item'
|
||||
description: 'Testing with large strings'
|
||||
kvs_id: 999999
|
||||
key: large_key
|
||||
value: large_value
|
||||
kvs_id: 999999
|
||||
key: large_key
|
||||
value: large_value
|
||||
)!
|
||||
|
||||
large_item = item_db.set(large_item)!
|
||||
@@ -191,11 +201,11 @@ fn test_userkvsitem_edge_cases() {
|
||||
special_value := 'value_with_unicode_💎_and_newlines\n\r\t'
|
||||
|
||||
mut special_item := item_db.new(
|
||||
name: 'Special Characters Item'
|
||||
name: 'Special Characters Item'
|
||||
description: 'Testing special characters'
|
||||
kvs_id: 1
|
||||
key: special_key
|
||||
value: special_value
|
||||
kvs_id: 1
|
||||
key: special_key
|
||||
value: special_value
|
||||
)!
|
||||
|
||||
special_item = item_db.set(special_item)!
|
||||
@@ -203,4 +213,4 @@ fn test_userkvsitem_edge_cases() {
|
||||
|
||||
assert retrieved_special.key == special_key
|
||||
assert retrieved_special.value == special_value
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user