github.com/koko1123/flow-go-1@v0.29.6/utils/debug/README.md (about) 1 2 3 ## Remote Debugger 4 5 Remote debugger provides utils needed to run transactions and scripts against live network data. It uses GRPC endpoints on an execution nodes to fetch registers and block info when running a transaction. This is mostly provided for debugging purpose and should not be used for production level operations. 6 If you use the caching method you can run the transaction once and use the cached values to run transaction in debugging mode. 7 8 ### sample code 9 10 ```GO 11 package debug_test 12 13 import ( 14 "fmt" 15 "os" 16 "testing" 17 18 "github.com/rs/zerolog" 19 "github.com/stretchr/testify/require" 20 21 "github.com/onflow/flow-go/model/flow" 22 "github.com/onflow/flow-go/utils/debug" 23 ) 24 25 func TestDebugger_RunTransaction(t *testing.T) { 26 27 grpcAddress := "localhost:3600" 28 chain := flow.Emulator.Chain() 29 debugger := debug.NewRemoteDebugger(grpcAddress, chain, zerolog.New(os.Stdout).With().Logger()) 30 31 const scriptTemplate = ` 32 import FlowServiceAccount from 0x%s 33 transaction() { 34 prepare(signer: AuthAccount) { 35 log(signer.balance) 36 } 37 } 38 ` 39 40 script := []byte(fmt.Sprintf(scriptTemplate, chain.ServiceAddress())) 41 txBody := flow.NewTransactionBody(). 42 SetGasLimit(9999). 43 SetScript([]byte(script)). 44 SetPayer(chain.ServiceAddress()). 45 SetProposalKey(chain.ServiceAddress(), 0, 0) 46 txBody.Authorizers = []flow.Address{chain.ServiceAddress()} 47 48 // Run at the latest blockID 49 txErr, err := debugger.RunTransaction(txBody) 50 require.NoError(t, txErr) 51 require.NoError(t, err) 52 53 // Run with blockID (use the file cache) 54 blockId, err := flow.HexStringToIdentifier("3a8281395e2c1aaa3b8643d148594b19e2acb477611a8e0cab8a55c46c40b563") 55 require.NoError(t, err) 56 txErr, err = debugger.RunTransactionAtBlockID(txBody, blockId, "") 57 require.NoError(t, txErr) 58 require.NoError(t, err) 59 60 testCacheFile := "test.cache" 61 defer os.Remove(testCacheFile) 62 // the first run would cache the results 63 txErr, err = debugger.RunTransactionAtBlockID(txBody, blockId, testCacheFile) 64 require.NoError(t, txErr) 65 require.NoError(t, err) 66 67 // second one should only use the cache 68 // make blockId invalid so if it endsup looking up by id it should fail 69 blockId = flow.Identifier{} 70 txErr, err = debugger.RunTransactionAtBlockID(txBody, blockId, testCacheFile) 71 require.NoError(t, txErr) 72 require.NoError(t, err) 73 } 74 75 76 ```