github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/deploy/def/job_test.go (about)

     1  package def
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/hyperledger/burrow/acm"
     8  	"github.com/hyperledger/burrow/execution/evm/abi"
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestJob_Validate(t *testing.T) {
    14  	address := acm.GeneratePrivateAccountFromSecret("blah").GetAddress()
    15  	job := &Job{
    16  		Result: "brian",
    17  		// This should pass emptiness validation
    18  		Variables: []*abi.Variable{},
    19  		QueryAccount: &QueryAccount{
    20  			Account: address.String(),
    21  			Field:   "bar",
    22  		},
    23  	}
    24  	err := job.Validate()
    25  	require.Error(t, err)
    26  	errs := strings.Split(err.Error(), ";")
    27  	if !assert.Len(t, errs, 2, "Should have two validation error from omitted name and included result") {
    28  		t.Logf("Validation error was: %v", err)
    29  	}
    30  
    31  	job = &Job{
    32  		Name: "Any kind of job",
    33  		Account: &Account{
    34  			Address: address.String(),
    35  		},
    36  	}
    37  	err = job.Validate()
    38  	require.NoError(t, err)
    39  
    40  	job.Account.Address = "blah"
    41  	err = job.Validate()
    42  	require.NoError(t, err)
    43  }