mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Effective amounts add missing checks
This commit is contained in:
@@ -1107,6 +1107,20 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
|||||||
tx.EffectiveAmount = big.NewInt(0)
|
tx.EffectiveAmount = big.NewInt(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if tx.TokenID==receiver.TokenID
|
||||||
|
accReceiver, err := s.GetAccount(tx.ToIdx)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: can not get account for tx.ToIdx: %d", tx.ToIdx)
|
||||||
|
tx.EffectiveDepositAmount = big.NewInt(0)
|
||||||
|
tx.EffectiveAmount = big.NewInt(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tx.TokenID != accReceiver.TokenID {
|
||||||
|
log.Debugf("EffectiveAmount = 0: tx TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accReceiver.TokenID)
|
||||||
|
tx.EffectiveAmount = big.NewInt(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1159,8 +1173,12 @@ func (s *StateDB) computeEffectiveAmounts(tx *common.L1Tx) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if accSender.TokenID != accReceiver.TokenID {
|
if accSender.TokenID != accReceiver.TokenID {
|
||||||
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)", accSender.TokenID, accReceiver.TokenID)
|
log.Debugf("EffectiveAmount = 0: sender account TokenID (%d) != receiver account TokenID (%d)", accSender.TokenID, accReceiver.TokenID)
|
||||||
tx.EffectiveDepositAmount = big.NewInt(0)
|
tx.EffectiveAmount = big.NewInt(0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if tx.TokenID != accReceiver.TokenID {
|
||||||
|
log.Debugf("EffectiveAmount & EffectiveDepositAmount = 0: tx TokenID (%d) != receiver account TokenID (%d)", tx.TokenID, accReceiver.TokenID)
|
||||||
tx.EffectiveAmount = big.NewInt(0)
|
tx.EffectiveAmount = big.NewInt(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,40 @@ func TestComputeEffectiveAmounts(t *testing.T) {
|
|||||||
sdb.computeEffectiveAmounts(&tx)
|
sdb.computeEffectiveAmounts(&tx)
|
||||||
assert.Equal(t, big.NewInt(8), tx.EffectiveDepositAmount)
|
assert.Equal(t, big.NewInt(8), tx.EffectiveDepositAmount)
|
||||||
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||||
|
|
||||||
|
// CreateAccountDepositTransfer for TokenID=1 when receiver does not
|
||||||
|
// have an account for that TokenID, expect that the
|
||||||
|
// EffectiveDepositAmount=DepositAmount, but EffectiveAmount==0
|
||||||
|
tx = common.L1Tx{
|
||||||
|
FromIdx: 0,
|
||||||
|
ToIdx: 257,
|
||||||
|
Amount: big.NewInt(8),
|
||||||
|
DepositAmount: big.NewInt(8),
|
||||||
|
FromEthAddr: tc.Users["A"].Addr,
|
||||||
|
TokenID: 2,
|
||||||
|
UserOrigin: true,
|
||||||
|
Type: common.TxTypeCreateAccountDepositTransfer,
|
||||||
|
}
|
||||||
|
sdb.computeEffectiveAmounts(&tx)
|
||||||
|
assert.Equal(t, big.NewInt(8), tx.EffectiveDepositAmount)
|
||||||
|
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||||
|
|
||||||
|
// DepositTransfer for TokenID=1 when receiver does not have an account
|
||||||
|
// for that TokenID, expect that the
|
||||||
|
// EffectiveDepositAmount=DepositAmount, but EffectiveAmount=0
|
||||||
|
tx = common.L1Tx{
|
||||||
|
FromIdx: 258,
|
||||||
|
ToIdx: 256,
|
||||||
|
Amount: big.NewInt(8),
|
||||||
|
DepositAmount: big.NewInt(8),
|
||||||
|
FromEthAddr: tc.Users["C"].Addr,
|
||||||
|
TokenID: 1,
|
||||||
|
UserOrigin: true,
|
||||||
|
Type: common.TxTypeDepositTransfer,
|
||||||
|
}
|
||||||
|
sdb.computeEffectiveAmounts(&tx)
|
||||||
|
assert.Equal(t, big.NewInt(8), tx.EffectiveDepositAmount)
|
||||||
|
assert.Equal(t, big.NewInt(0), tx.EffectiveAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessTxsBalances(t *testing.T) {
|
func TestProcessTxsBalances(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user