@@ -134,7 +134,7 @@ func testImpl(t *testing.T, prog *program.Program, expected CaseResult, exec fun
134134
135135 err := exec (m )
136136 if expected .Error != nil {
137- require .True (t , errors .Is (err , expected .Error ), "got wrong error, want: %v , got: %v" , expected .Error , err )
137+ require .True (t , errors .Is (err , expected .Error ), "got wrong error, want: %[1]v (%[1]T) , got: %v" , expected .Error , err )
138138 if expected .ErrorContains != "" {
139139 require .ErrorContains (t , err , expected .ErrorContains )
140140 }
@@ -1699,6 +1699,54 @@ func TestVariablesErrors(t *testing.T) {
16991699 test (t , tc )
17001700}
17011701
1702+ func TestWorldSourceVariable (t * testing.T ) {
1703+ tc := NewTestCase ()
1704+ tc .compile (t , `vars {
1705+ account $foo
1706+ }
1707+ send [COIN 1] (
1708+ source = $foo
1709+ destination = @bob
1710+ )` )
1711+ tc .vars = map [string ]string {
1712+ "foo" : "world" ,
1713+ }
1714+ tc .expected = CaseResult {
1715+ Printed : []machine.Value {},
1716+ Postings : []Posting {},
1717+ Error : & machine.ErrInvalidVars {},
1718+ ErrorContains : "`@world` can only be used as a variable in the experimental interpreter, or if it is never used as a source" ,
1719+ }
1720+ test (t , tc )
1721+ }
1722+
1723+ func TestWorldNonSourceVariable (t * testing.T ) {
1724+ tc := NewTestCase ()
1725+ tc .compile (t , `vars {
1726+ account $foo
1727+ }
1728+ send [COIN 1] (
1729+ source = @alice
1730+ destination = $foo
1731+ )` )
1732+ tc .setBalance ("alice" , "COIN" , 1 )
1733+ tc .vars = map [string ]string {
1734+ "foo" : "world" ,
1735+ }
1736+ tc .expected = CaseResult {
1737+ Printed : []machine.Value {},
1738+ Postings : []Posting {
1739+ {
1740+ Source : "alice" ,
1741+ Destination : "world" ,
1742+ Asset : "COIN" ,
1743+ Amount : machine .NewMonetaryInt (1 ),
1744+ },
1745+ },
1746+ }
1747+ test (t , tc )
1748+ }
1749+
17021750func TestSetVarsFromJSON (t * testing.T ) {
17031751
17041752 type testCase struct {
@@ -2267,6 +2315,25 @@ func TestSaveFromAccount(t *testing.T) {
22672315 }
22682316 test (t , tc )
22692317 })
2318+
2319+ t .Run ("save all and overdraft" , func (t * testing.T ) {
2320+ script := `
2321+ save [USD *] from @alice
2322+
2323+ send [USD 10] (
2324+ source = @alice allowing overdraft up to [USD 10]
2325+ destination = @world
2326+ )`
2327+ tc := NewTestCase ()
2328+ tc .compile (t , script )
2329+ tc .setBalance ("alice" , "USD" , - 10 )
2330+ tc .expected = CaseResult {
2331+ Printed : []machine.Value {},
2332+ ErrorContains : "insufficient funds" ,
2333+ Error : & machine.ErrInsufficientFund {},
2334+ }
2335+ test (t , tc )
2336+ })
22702337}
22712338
22722339func TestUseDifferentAssetsWithSameSourceAccount (t * testing.T ) {
0 commit comments