@@ -1459,6 +1459,27 @@ func TestDestinationComplex(t *testing.T) {
1459
1459
1460
1460
// TODO TestNeededBalances, TestSetTxMeta, TestSetAccountMeta
1461
1461
1462
+ func TestSendZero (t * testing.T ) {
1463
+ tc := NewTestCase ()
1464
+ tc .compile (t , `
1465
+ send [COIN 0] (
1466
+ source = @src
1467
+ destination = @dest
1468
+ )` )
1469
+ tc .expected = CaseResult {
1470
+ Postings : []Posting {
1471
+ {
1472
+ Asset : "COIN" ,
1473
+ Amount : big .NewInt (0 ),
1474
+ Source : "src" ,
1475
+ Destination : "dest" ,
1476
+ },
1477
+ },
1478
+ Error : nil ,
1479
+ }
1480
+ test (t , tc )
1481
+ }
1482
+
1462
1483
func TestBalance (t * testing.T ) {
1463
1484
tc := NewTestCase ()
1464
1485
tc .compile (t , `
@@ -1485,6 +1506,52 @@ func TestBalance(t *testing.T) {
1485
1506
test (t , tc )
1486
1507
}
1487
1508
1509
+ func TestNegativeBalance (t * testing.T ) {
1510
+ tc := NewTestCase ()
1511
+ tc .compile (t , `
1512
+ vars {
1513
+ monetary $balance = balance(@a, EUR/2)
1514
+ }
1515
+
1516
+ send $balance (
1517
+ source = @world
1518
+ destination = @dest
1519
+ )` )
1520
+ tc .setBalance ("a" , "EUR/2" , - 100 )
1521
+ tc .expected = CaseResult {
1522
+ Error : machine.NegativeBalanceError {
1523
+ Account : "a" ,
1524
+ Amount : * big .NewInt (- 100 ),
1525
+ },
1526
+ }
1527
+ test (t , tc )
1528
+ }
1529
+
1530
+ func TestBalanceNotFound (t * testing.T ) {
1531
+ tc := NewTestCase ()
1532
+ tc .compile (t , `
1533
+ vars {
1534
+ monetary $balance = balance(@a, EUR/2)
1535
+ }
1536
+
1537
+ send $balance (
1538
+ source = @world
1539
+ destination = @dest
1540
+ )` )
1541
+ tc .expected = CaseResult {
1542
+ Postings : []Posting {
1543
+ {
1544
+ Asset : "EUR/2" ,
1545
+ Amount : big .NewInt (0 ),
1546
+ Source : "world" ,
1547
+ Destination : "dest" ,
1548
+ },
1549
+ },
1550
+ Error : nil ,
1551
+ }
1552
+ test (t , tc )
1553
+ }
1554
+
1488
1555
func TestInoderDestination (t * testing.T ) {
1489
1556
tc := NewTestCase ()
1490
1557
tc .compile (t , `send [COIN 100] (
@@ -1695,16 +1762,19 @@ func TestVariableBalance(t *testing.T) {
1695
1762
tc := NewTestCase ()
1696
1763
script = `
1697
1764
vars {
1698
- monetary $amount = balance(@world , USD/2)
1765
+ monetary $amount = balance(@src , USD/2)
1699
1766
}
1700
1767
send $amount (
1701
1768
source = @A
1702
1769
destination = @B
1703
1770
)`
1704
1771
tc .compile (t , script )
1705
- tc .setBalance ("world " , "USD/2" , - 40 )
1772
+ tc .setBalance ("src " , "USD/2" , - 40 )
1706
1773
tc .expected = CaseResult {
1707
- Error : machine.NegativeAmountErr {Amount : machine .NewMonetaryInt (- 40 )},
1774
+ Error : machine.NegativeBalanceError {
1775
+ Account : "src" ,
1776
+ Amount : * big .NewInt (- 40 ),
1777
+ },
1708
1778
}
1709
1779
test (t , tc )
1710
1780
})
0 commit comments