Skip to content

Commit

Permalink
Fixes tokens sdk fuzzer (#3662)
Browse files Browse the repository at this point in the history
* Fixes tokens sdk fuzzer

* Prepares for the rest

* status fuzzer

* Changes
  • Loading branch information
tjayrush authored May 8, 2024
1 parent f983081 commit ba1737c
Show file tree
Hide file tree
Showing 20 changed files with 327 additions and 208 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This file details changes made to TrueBlocks over time. See the [migration notes

## v3.0.0 (2024/04/31)

- SDK
- Instructions for re-building:
- remove .cmake in ./build folder
- remove ./go.work and go.work.sum in root
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/chunks/handle_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (opts *ChunksOptions) HandleTag(blockNums []base.Blknum) error {
return
}
bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode,
Enabled: !testMode && !logger.IsTerminal(),
Total: int64(len(man.Chunks)),
})
tagIndex := func(walker *walk.CacheWalker, path string, first bool) (bool, error) {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/internal/chunks/handle_truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (opts *ChunksOptions) HandleTruncate(blockNums []base.Blknum) error {
_ = file.CleanFolder(chain, config.PathToIndex(chain), []string{"ripe", "unripe", "maps", "staging"})

bar := logger.NewBar(logger.BarOptions{
Enabled: !testMode,
Enabled: !testMode && !logger.IsTerminal(),
Total: 128,
Type: logger.Expanding,
})
Expand Down Expand Up @@ -98,7 +98,7 @@ func (opts *ChunksOptions) HandleTruncate(blockNums []base.Blknum) error {
bar.Prefix = fmt.Sprintf("Truncated to %d ", opts.Truncate)
bar.Finish(true /* newLine */)
bar = logger.NewBar(logger.BarOptions{
Enabled: !testMode,
Enabled: !testMode && !logger.IsTerminal(),
Total: 20,
Type: logger.Expanding,
})
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/scrape/handle_touch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (

func (opts *ScrapeOptions) HandleTouch() error {
// TODO: implement
logger.Error("Not implemented yet.")
logger.Error("chifra scrape --touch is not yet implemented")
return nil
}
5 changes: 0 additions & 5 deletions src/apps/chifra/internal/state/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package statePkg
import (
"errors"
"fmt"
"strings"

"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/call"
Expand Down Expand Up @@ -35,10 +34,6 @@ func (opts *StateOptions) validateState() error {
return err
}

if strings.Contains(strings.Join(opts.Parts, " "), "nonce") {
return validate.Usage("The {0} value is currently not available{1}.", "nonce", " with the --parts option")
}

if len(opts.Globals.File) > 0 {
// do nothing for now

Expand Down
6 changes: 4 additions & 2 deletions src/apps/chifra/internal/status/handle_caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/tslib"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/types"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/walk"
)

Expand Down Expand Up @@ -98,16 +99,17 @@ func (opts *StatusOptions) HandleCaches() error {
result.Data.(*CacheWalker).cancel()
}

smallMark := result.Data.(*CacheWalker).nSeen%100 == 0
logger.Progress(
result.Data.(*CacheWalker).nSeen%100 == 0,
smallMark && !utils.IsFuzzing(),
fmt.Sprintf("Found %d %s files", counterMap[cT].NFiles, cT))

if (result.Data.(*CacheWalker).nSeen+1)%100000 == 0 {
logger.Info(colors.Green, "Progress:", colors.Off, "Found", counterMap[cT].NFiles, "files and", counterMap[cT].NFolders, "folders after", result.Data.(*CacheWalker).nSeen+1, "files")
}

} else {
logger.Progress(true, fmt.Sprintf("Skipped %s", result.Path))
logger.Progress(!utils.IsFuzzing(), fmt.Sprintf("Skipped %s", result.Path))
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/apps/chifra/internal/status/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ func (opts *StatusOptions) validateStatus() error {
return validate.Usage("{0} may not be used with {1}", "--diagnose", opts.Modes[0])
}

if len(opts.Modes) == 0 && opts.Chains {
return validate.Usage("The {0} option is only available{1}.", "--chains", " with a mode")
}

return opts.Globals.Validate()
}
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/tokens/handle_decache.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (

func (opts *TokensOptions) HandleDecache() error {
// TODO: implement
logger.Error("Not implemented yet.")
logger.Error("chifra tokens --decache is not yet implemented")
return nil
}
14 changes: 1 addition & 13 deletions src/apps/chifra/internal/tokens/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,7 @@ func (opts *TokensOptions) validateTokens() error {
}

if opts.Changes {
return validate.Usage("The {0} is not yet implemented.", "--changes")
}

if err != nil {
if invalidLiteral, ok := err.(*validate.InvalidIdentifierLiteralError); ok {
return invalidLiteral
}

if errors.Is(err, validate.ErrTooManyRanges) {
return validate.Usage("Specify only a single block range at a time.")
}

return err
return validate.Usage("The {0} option is not yet implemented.", "--changes")
}

if len(opts.Addrs) == 0 {
Expand Down
36 changes: 36 additions & 0 deletions src/dev_tools/sdkFuzzer/chunks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,42 @@ func DoChunks() {
LastBlock: 2000,
}
ShowHeader("ChunksManifest", &opts)

// BlockIds []string `json:"blocks,omitempty"`
// Check bool `json:"check,omitempty"`
// Pin bool `json:"pin,omitempty"`
// Publish bool `json:"publish,omitempty"`
// Publisher base.Address `json:"publisher,omitempty"`
// Remote bool `json:"remote,omitempty"`
// Belongs []string `json:"belongs,omitempty"`
// FirstBlock base.Blknum `json:"firstBlock,omitempty"`
// LastBlock base.Blknum `json:"lastBlock,omitempty"`
// MaxAddrs uint64 `json:"maxAddrs,omitempty"`
// Deep bool `json:"deep,omitempty"`
// Rewrite bool `json:"rewrite,omitempty"`
// List bool `json:"list,omitempty"`
// Unpin bool `json:"unpin,omitempty"`
// Count bool `json:"count,omitempty"`
// Sleep float64 `json:"sleep,omitempty"`
// func (opts *ChunksOptions) ChunksManifest() ([]types.ChunkManifest, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksIndex() ([]types.ChunkIndex, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksBlooms() ([]types.ChunkBloom, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksPins() ([]types.ChunkPin, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksAddresses() ([]types.ChunkAddress, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksAppearances() ([]types.ChunkAppearance, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksStats() ([]types.ChunkStats, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksTruncate(val base.Blknum) ([]types.Message, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksDiff() ([]types.Message, *types.MetaData, error) {
// func (opts *ChunksOptions) ChunksTag(val string) ([]types.Message, *types.MetaData, error) {
// NoCHM ChunksMode = 0
// CMManifest = 1 << iota
// CMIndex
// CMBlooms
// CMPins
// CMAddresses
// CMAppearances
// CMStats

if chunksManifest, _, err := opts.ChunksManifest(); err != nil {
logger.Error(err)
} else {
Expand Down
36 changes: 36 additions & 0 deletions src/dev_tools/sdkFuzzer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,42 @@ func DoExport() {
}
ShowHeader("DoExport", &opts)

// Addrs []string `json:"addrs,omitempty"`
// Topics []string `json:"topics,omitempty"`
// Fourbytes []string `json:"fourbytes,omitempty"`
// Accounting bool `json:"accounting,omitempty"`
// Articulate bool `json:"articulate,omitempty"`
// CacheTraces bool `json:"cacheTraces,omitempty"`
// FirstRecord uint64 `json:"firstRecord,omitempty"`
// MaxRecords uint64 `json:"maxRecords,omitempty"`
// Relevant bool `json:"relevant,omitempty"`
// Emitter []string `json:"emitter,omitempty"`
// Topic []string `json:"topic,omitempty"`
// Reverted bool `json:"reverted,omitempty"`
// Asset []string `json:"asset,omitempty"`
// Flow ExportFlow `json:"flow,omitempty"`
// Factory bool `json:"factory,omitempty"`
// Unripe bool `json:"unripe,omitempty"`
// Load string `json:"load,omitempty"`
// Reversed bool `json:"reversed,omitempty"`
// NoZero bool `json:"noZero,omitempty"`
// FirstBlock base.Blknum `json:"firstBlock,omitempty"`
// LastBlock base.Blknum `json:"lastBlock,omitempty"`
// func (opts *ExportOptions) Export() ([]types.Transaction, *types.MetaData, error) {
// func (opts *ExportOptions) ExportAppearances() ([]types.Appearance, *types.MetaData, error) {
// func (opts *ExportOptions) ExportReceipts() ([]types.Receipt, *types.MetaData, error) {
// func (opts *ExportOptions) ExportLogs() ([]types.Log, *types.MetaData, error) {
// func (opts *ExportOptions) ExportTraces() ([]types.Trace, *types.MetaData, error) {
// func (opts *ExportOptions) ExportNeighbors() ([]bool, *types.MetaData, error) {
// func (opts *ExportOptions) ExportStatements() ([]types.Statement, *types.MetaData, error) {
// func (opts *ExportOptions) ExportBalances() ([]types.State, *types.MetaData, error) {
// func (opts *ExportOptions) ExportWithdrawals() ([]types.Withdrawal, *types.MetaData, error) {
// func (opts *ExportOptions) ExportCount() ([]types.AppearanceCount, *types.MetaData, error) {
// NoEF ExportFlow = 0
// EFIn = 1 << iota
// EFOut
// EFZero

if export, _, err := opts.Export(); err != nil {
logger.Error(err)
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/dev_tools/sdkFuzzer/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ func getFilename(baseName string, g *sdk.Globals) string {
return "sdkFuzzer-output/" + baseName + app + ".json"
}

var spaces = strings.Repeat(" ", 20)
var spaces = strings.Repeat(" ", 30)

func ReportError(fn string, err error) {
logger.Error(fmt.Errorf("NO %s: %v%s", fn, err, spaces))
}

func ReportOkay(fn string) {
// logger.Progress(true, colors.Green, "OK ", fn, colors.Off, spaces)
logger.Info(colors.Green, "OK ", fn, colors.Off, spaces)
}

Expand All @@ -52,7 +53,7 @@ func ShowHeader(msg string, opts fmt.Stringer) {
func noCache(in []sdk.Globals) []sdk.Globals {
out := []sdk.Globals{}
for _, g := range in {
if !g.Cache && !g.Decache {
if !(g.Cache || g.Decache) {
out = append(out, g)
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/dev_tools/sdkFuzzer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ func DoInit() {

// opts := sdk.InitOptions{}

// Publisher base.Address `json:"publisher,omitempty"`
// FirstBlock base.Blknum `json:"firstBlock,omitempty"`
// Sleep float64 `json:"sleep,omitempty"`
// func (opts *InitOptions) InitAll() ([]bool, *types.MetaData, error) {
// func (opts *InitOptions) InitExample(val string) ([]bool, *types.MetaData, error) {
// func (opts *InitOptions) InitDry_run() ([]bool, *types.MetaData, error) {

// if init, _, err := opts.InitAll(); err != nil {
// logger.Error(err)
// } else {
Expand Down
25 changes: 13 additions & 12 deletions src/dev_tools/sdkFuzzer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ import (
)

func main() {
DoReceipts()
DoLogs()
DoTraces()
DoState()
DoAbis()
DoBlocks()
DoWhen()
DoList()
DoNames() // does not test crud commands
DoConfig()
DoTransactions()
// DoReceipts()
// DoLogs()
// DoTraces()
// DoState()
// DoAbis()
// DoBlocks()
// DoWhen()
// DoList()
// DoNames() // does not test crud commands
// DoConfig()
// DoTransactions()
// DoTokens()
// DoSlurp()

// DoChunks()
// DoExport()
// DoStatus()
DoStatus()

// DoInit()
// DoMonitors()

// DoDaemon - do not test daemon in fuzzer

// DoScrape - no sdk routines for scrape
// DoExplore - no sdk routines for explore
}
Expand Down
14 changes: 14 additions & 0 deletions src/dev_tools/sdkFuzzer/monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ func DoMonitors() {
}
ShowHeader("DoMonitors", &opts)

// Addrs []string `json:"addrs,omitempty"`
// Delete bool `json:"delete,omitempty"`
// Undelete bool `json:"undelete,omitempty"`
// Remove bool `json:"remove,omitempty"`
// Watch bool `json:"watch,omitempty"`
// Watchlist string `json:"watchlist,omitempty"`
// Commands string `json:"commands,omitempty"`
// BatchSize uint64 `json:"batchSize,omitempty"`
// RunCount uint64 `json:"runCount,omitempty"`
// Sleep float64 `json:"sleep,omitempty"`
// func (opts *MonitorsOptions) Monitors() ([]bool, *types.MetaData, error) {
// func (opts *MonitorsOptions) MonitorsClean() ([]types.MonitorClean, *types.MetaData, error) {
// func (opts *MonitorsOptions) MonitorsList() ([]types.Monitor, *types.MetaData, error) {

if monitors, _, err := opts.MonitorsList(); err != nil {
logger.Error(err)
} else {
Expand Down
29 changes: 29 additions & 0 deletions src/dev_tools/sdkFuzzer/slurp.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,32 @@ func DoSlurp() {
}

}

// Addrs []string `json:"addrs,omitempty"`
// BlockIds []string `json:"blocks,omitempty"`
// Types SlurpTypes `json:"types,omitempty"`
// Articulate bool `json:"articulate,omitempty"`
// Source SlurpSource `json:"source,omitempty"`
// Page uint64 `json:"page,omitempty"`
// PageId string `json:"pageId,omitempty"`
// PerPage uint64 `json:"perPage,omitempty"`
// Sleep float64 `json:"sleep,omitempty"`
// func (opts *SlurpOptions) Slurp() ([]types.Slurp, *types.MetaData, error) {
// func (opts *SlurpOptions) SlurpAppearances() ([]types.Appearance, *types.MetaData, error) {
// func (opts *SlurpOptions) SlurpCount() ([]types.SlurpCount, *types.MetaData, error) {
// NoST SlurpTypes = 0
// STExt = 1 << iota
// STInt
// STToken
// STNfts
// ST1155
// STMiner
// STUncles
// STWithdrawals
// STSome = STExt | STInt | STToken | STNfts
// STAll = STExt | STInt | STToken | STNfts | ST1155 | STMiner | STUncles | STWithdrawals
// NoSS SlurpSource = 0
// SSEtherscan = 1 << iota
// SSKey
// SSCovalent
// SSAlchemy
3 changes: 2 additions & 1 deletion src/dev_tools/sdkFuzzer/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func DoState() {
changes := []bool{false, true}
noZeros := []bool{false, true}
parts := []sdk.StateParts{
sdk.SPBalance, /*sdk.SPNonce,*/
sdk.SPBalance,
sdk.SPNonce,
sdk.SPCode,
sdk.SPProxy,
sdk.SPDeployed,
Expand Down
Loading

0 comments on commit ba1737c

Please sign in to comment.