Skip to content

Commit

Permalink
Fix method SafeInt64ToUint64.
Browse files Browse the repository at this point in the history
  • Loading branch information
irina-pereiaslavskaia committed Oct 17, 2024
2 parents 58162cc + b07b287 commit 306399d
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 71 deletions.
11 changes: 11 additions & 0 deletions pkg/settings/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ var FeaturesInfo = map[Feature]FeatureInfo{
BoostBlockReward: {true, "Boost Block Reward"},
InvokeExpression: {false, "InvokeExpression"},
}

// LastFeature returns the last implemented feature.
func LastFeature() Feature {
var f Feature
for feature, info := range FeaturesInfo {
if info.Implemented {
f = max(f, feature)
}
}
return f
}
56 changes: 50 additions & 6 deletions pkg/state/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,9 @@ func createStorageObjects(t *testing.T, amend bool) *testStorageObjects {
}

type testStorageObjectsOptions struct {
Amend bool
Settings *settings.BlockchainSettings
Amend bool
Settings *settings.BlockchainSettings
CalculateHashes bool
}

func createStorageObjectsWithOptions(t *testing.T, options testStorageObjectsOptions) *testStorageObjects {
Expand Down Expand Up @@ -388,7 +389,7 @@ func createStorageObjectsWithOptions(t *testing.T, options testStorageObjectsOpt
hs, err := newHistoryStorage(db, dbBatch, stateDB, options.Amend)
require.NoError(t, err)

entities, err := newBlockchainEntitiesStorage(hs, options.Settings, rw, false)
entities, err := newBlockchainEntitiesStorage(hs, options.Settings, rw, options.CalculateHashes)
require.NoError(t, err)

return &testStorageObjects{db, dbBatch, rw, hs, stateDB, options.Settings, entities}
Expand Down Expand Up @@ -454,6 +455,12 @@ func (s *testStorageObjects) finishBlock(t *testing.T, blockID proto.BlockID) {
assert.NoError(t, err, "finishBlock() failed")
}

func (s *testStorageObjects) addBlockAndDo(t *testing.T, blockID proto.BlockID, f func(proto.BlockID)) {
s.prepareAndStartBlock(t, blockID)
f(blockID)
s.finishBlock(t, blockID)
}

func (s *testStorageObjects) addBlocks(t *testing.T, blocksNum int) {
ids := genRandBlockIds(t, blocksNum)
for _, id := range ids {
Expand Down Expand Up @@ -504,6 +511,39 @@ func (s *testStorageObjects) createSmartAsset(t *testing.T, assetID crypto.Diges
s.flush(t)
}

func (s *testStorageObjects) setWavesBalance(
t *testing.T,
addr proto.WavesAddress,
bp balanceProfile,
blockID proto.BlockID,
) {
wb := newWavesValueFromProfile(bp)
err := s.entities.balances.setWavesBalance(addr.ID(), wb, blockID)
assert.NoError(t, err, "setWavesBalance() failed")
}

func (s *testStorageObjects) transferWaves(
t *testing.T,
from, to proto.WavesAddress,
amount uint64,
blockID proto.BlockID,
) {
fromBP, err := s.entities.balances.newestWavesBalance(from.ID())
require.NoError(t, err, "newestWavesBalance() failed")
if fromBalance := fromBP.spendableBalance(); fromBalance < amount {
require.Failf(t, "transferWaves()", "not enough balance at account '%s': %d < %d",
from.String(), fromBalance, amount,
)
}
fromBP.balance -= amount
s.setWavesBalance(t, from, fromBP, blockID)

toBalance, err := s.entities.balances.newestWavesBalance(to.ID())
require.NoError(t, err, "newestWavesBalance() failed")
toBalance.balance += amount
s.setWavesBalance(t, to, toBalance, blockID)
}

func storeScriptByAddress(
stor *blockchainEntitiesStorage,
scheme proto.Scheme,
Expand Down Expand Up @@ -542,11 +582,15 @@ func (s *testStorageObjects) setScript(t *testing.T, pk crypto.PublicKey, script
require.NoError(t, err)
}

func (s *testStorageObjects) activateFeature(t *testing.T, featureID int16) {
s.addBlock(t, blockID0)
func (s *testStorageObjects) activateFeatureWithBlock(t *testing.T, featureID int16, blockID proto.BlockID) {
activationReq := &activatedFeaturesRecord{1}
err := s.entities.features.activateFeature(featureID, activationReq, blockID0)
err := s.entities.features.activateFeature(featureID, activationReq, blockID)
assert.NoError(t, err, "activateFeature() failed")
}

func (s *testStorageObjects) activateFeature(t *testing.T, featureID int16) {
s.addBlock(t, blockID0)
s.activateFeatureWithBlock(t, featureID, blockID0)
s.flush(t)
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/state/script_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,13 @@ func (a *scriptCaller) invokeFunctionByEthereumTx(
}
// Since V5 we have to create environment with wrapped state to which we put attached payments
if tree.LibVersion >= ast.LibV5 {
const checkSenderBalance = false // skip initial payments validation for eth tx, see PR #965 for more info
//TODO: Update last argument of the followinxg call with new feature activation flag or
// something else depending on NODE-2531 issue resolution in scala implementation.
isPbTx := proto.IsProtobufTx(tx)
env, err = ride.NewEnvironmentWithWrappedState(env, a.state, scriptPayments, sender, isPbTx, tree.LibVersion, false)
env, err = ride.NewEnvironmentWithWrappedState(env, a.state, scriptPayments, sender,
isPbTx, tree.LibVersion, checkSenderBalance,
)
if err != nil {
return nil, proto.FunctionCall{}, errors.Wrap(err, "failed to create RIDE environment with wrapped state")
}
Expand Down
Loading

0 comments on commit 306399d

Please sign in to comment.