Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions internal/interpreter/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,12 @@ func CompareBalances(b1 Balances, b2 Balances) bool {
return ab1.Cmp(ab2) == 0
})
}

// Returns whether the second value is a subset of the first one
func CompareBalancesIncluding(b1 Balances, b2 Balances) bool {
return utils.MapIncludes(b1, b2, func(a1 AccountBalance, a2 AccountBalance) bool {
return utils.MapIncludes(a1, a2, func(i1 *big.Int, i2 *big.Int) bool {
return i1.Cmp(i2) == 0
})
})
}
64 changes: 64 additions & 0 deletions internal/interpreter/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,67 @@ func TestCmpMaps(t *testing.T) {

require.Equal(t, false, CompareBalances(b1, b2))
}

func TestCmpMapsIncluding(t *testing.T) {

t.Run("including (subset)", func(t *testing.T) {
b1 := Balances{
"alice": AccountBalance{
"EUR": big.NewInt(100),
},
"bob": AccountBalance{
"EUR": big.NewInt(100),
},
}

b2 := Balances{
"alice": AccountBalance{
"EUR": big.NewInt(100),
},
}

require.Equal(t, true, CompareBalancesIncluding(b1, b2))
})

t.Run("different value", func(t *testing.T) {
b1 := Balances{
"alice": AccountBalance{
"EUR": big.NewInt(100),
},
"bob": AccountBalance{
"EUR": big.NewInt(100),
},
}

b2 := Balances{
"alice": AccountBalance{
"EUR": big.NewInt(0),
},
}

require.Equal(t, false, CompareBalancesIncluding(b1, b2))
})

t.Run("extra value", func(t *testing.T) {
b1 := Balances{
"alice": AccountBalance{
"EUR": big.NewInt(100),
},
"bob": AccountBalance{
"EUR": big.NewInt(100),
},
}

b2 := Balances{
"alice": AccountBalance{
"EUR": big.NewInt(100),
},

"extra-value": AccountBalance{
"EUR": big.NewInt(100),
},
}

require.Equal(t, false, CompareBalancesIncluding(b1, b2))
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"USD": 4
}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"it": "should send the missing amount to an overdraft account",
"balances": { "alice": { "EUR": -100 } },
"expect.volumes": {
"expect.endBalances": {
"alice": { "EUR": 0 },
"world": { "EUR": -100 }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"wallet": { "EUR": 50 },
"bank_account": { "EUR": -100 }
},
"expect.missingFunds": true
"expect.error.missingFunds": true
},
{
"it": "should not authorize transfer if bank account does not display enough balance and wallet does",
"balances": {
"wallet": { "EUR": 100 },
"bank_account": { "EUR": -50 }
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"EUR/2": 51
}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"featureFlags": [
"experimental-asset-colors"
],
"featureFlags": ["experimental-asset-colors"],
"testCases": [
{
"it": "-",
Expand All @@ -11,7 +9,7 @@
"COIN_RED": 1
}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"featureFlags": [
"experimental-oneof"
],
"featureFlags": ["experimental-oneof"],
"testCases": [
{
"it": "-",
Expand All @@ -10,7 +8,7 @@
"empty2": {},
"empty3": {}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"payment": "payments:001",
"seller": "users:002"
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"COIN": 1
}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"USD/2": 30
}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"COIN": 1
}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"COIN": 60
}
},
"expect.missingFunds": true
"expect.error.missingFunds": true
}
]
}
30 changes: 26 additions & 4 deletions internal/specs_format/__snapshots__/runner_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
---

[TestSingleTest - 1]
❯ example.num (2 tests | 1 failed)
❯ example.num (2 tests | 1 failed)
× tfailing
✓ tpassing


 FAIL  example.num.specs.json > tfailing

GOT:

| Source | Destination | Asset | Amount |
| world | dest | USD/2 | 100 |


- Expected
+ Received
Expand All @@ -37,8 +44,9 @@
---

[TestComplexAssertions - 1]
❯ example.num (2 tests | 1 failed)
❯ example.num (2 tests | 1 failed)
× send when there are enough funds
✓ tpassing


 FAIL  example.num.specs.json > send when there are enough funds
Expand All @@ -48,16 +56,22 @@ GIVEN:
| Account | Asset | Balance |
| alice | USD/2 | 9999 |


GOT:

| Source | Destination | Asset | Amount |
| alice | dest | USD/2 | 100 |


- Expected
+ Received

expect.missingFunds
expect.error.missingFunds

- true
+ false

expect.volumes
expect.endBalances

 {
 "alice": {
Expand Down Expand Up @@ -136,3 +150,11 @@ Error: example.num:1:29
| ~~~~~~

---

[TestFocusUi - 1]
✓ example.num (2 tests | 1 skipped)

 Test files  1 passed (1)
 Tests  1 passed | 1 skipped (2)

---
Loading