github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/forensics/revert_test.go (about)

     1  // +build forensics
     2  
     3  package forensics
     4  
     5  import (
     6  	"bytes"
     7  	"fmt"
     8  	"io/ioutil"
     9  	"path"
    10  	"testing"
    11  
    12  	"github.com/hyperledger/burrow/execution/exec"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  const devStudioPath = "/home/silas/burrows/t7-dev-studio-burrow-000/t7-dev-studio-burrow-000"
    17  
    18  func testLoadStudio(t *testing.T, i int) {
    19  	re := newReplay(t, studioDir(i))
    20  	bc, err := re.LatestBlockchain()
    21  	require.NoError(t, err)
    22  	fmt.Println(bc.LastBlockHeight())
    23  
    24  	st, err := re.State(bc.LastBlockHeight())
    25  	require.NoError(t, err)
    26  
    27  	fmt.Printf("Validator %d hash: %X\n", i, st.Hash())
    28  	//txHash := hex.MustDecodeString("DEF358F2CD8746CC2CEADE6EDF6518699FA91C512C45A3894FBB0E746E57B749")
    29  
    30  	accum := exec.NewBlockAccumulator()
    31  	buf := new(bytes.Buffer)
    32  	err = st.IterateStreamEvents(nil, nil, func(ev *exec.StreamEvent) error {
    33  		be, err := accum.Consume(ev)
    34  		if err != nil {
    35  			return err
    36  		}
    37  		if be != nil {
    38  			buf.WriteString(fmt.Sprintf("Block %d: %X\n\n", be.Height, be.Header.AppHash))
    39  			for _, txe := range be.TxExecutions {
    40  				if txe.Exception != nil {
    41  					buf.WriteString(fmt.Sprintf("Tx %v: %v\n\n", txe.TxExecutions, txe.Exception))
    42  				}
    43  			}
    44  		}
    45  		return nil
    46  	})
    47  	require.NoError(t, err)
    48  
    49  	err = ioutil.WriteFile(fmt.Sprintf("test-out-%d.txt", i), buf.Bytes(), 0644)
    50  	require.NoError(t, err)
    51  }
    52  
    53  func TestStudioTx0(t *testing.T) {
    54  	testLoadStudio(t, 0)
    55  }
    56  
    57  func TestStudioTx(t *testing.T) {
    58  	for i := 0; i < 4; i++ {
    59  		burrowDir := studioDir(i)
    60  		fmt.Println(burrowDir)
    61  		testLoadStudio(t, i)
    62  	}
    63  }
    64  
    65  func studioDir(i int) string {
    66  	return path.Join(devStudioPath, fmt.Sprintf("%03d", i))
    67  }