Skip to content

Commit

Permalink
Merge pull request #1372 from jhkimqd/jihwan/policymapping-test
Browse files Browse the repository at this point in the history
test: add unit tests for txpool/policy policyMapping
  • Loading branch information
jhkimqd authored Oct 30, 2024
2 parents 1c40bd7 + cb93848 commit a4d55d8
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions zk/txpool/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,51 @@ func TestRemovePolicy(t *testing.T) {
})
}

func TestPolicyMapping(t *testing.T) {
// All policies
var policiesAll []byte
var pListAll []Policy
policiesAll = append(policiesAll, SendTx.ToByte())
policiesAll = append(policiesAll, Deploy.ToByte())
pListAll = append(pListAll, SendTx)
pListAll = append(pListAll, Deploy)

// Only sendTx policy
var policiesSendTx []byte
var pListSendTx []Policy
policiesSendTx = append(policiesSendTx, SendTx.ToByte())
pListSendTx = append(pListSendTx, SendTx)

// Only deploy policy
var policiesDeploy []byte
var pListDeploy []Policy
policiesDeploy = append(policiesDeploy, Deploy.ToByte())
pListDeploy = append(pListDeploy, Deploy)

// No policy
var policiesNone []byte
var pListNone []Policy

var tests = []struct {
policies []byte
pList []Policy
want string
}{
{policiesAll, pListAll, "\tsendTx: true\n\tdeploy: true"},
{policiesSendTx, pListSendTx, "\tsendTx: true"},
{policiesDeploy, pListDeploy, "\tdeploy: true"},
{policiesNone, pListNone, ""},
}
for _, tt := range tests {
t.Run("PolicyMapping", func(t *testing.T) {
ans := policyMapping(tt.policies, tt.pList)
if ans != tt.want {
t.Errorf("got %v, want %v", ans, tt.want)
}
})
}
}

func TestAddPolicy(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit a4d55d8

Please sign in to comment.