From 5036b349cb973b3c480839689dd51a5e5e197e83 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Tue, 30 Nov 2021 13:16:47 +0000 Subject: [PATCH] Adapt trie code to use `Type()` before type assertions --- lib/trie/branch/type.go | 12 ---------- lib/trie/branch/type_test.go | 46 ------------------------------------ lib/trie/leaf/type.go | 8 ------- lib/trie/leaf/type_test.go | 18 -------------- 4 files changed, 84 deletions(-) delete mode 100644 lib/trie/branch/type.go delete mode 100644 lib/trie/branch/type_test.go delete mode 100644 lib/trie/leaf/type.go delete mode 100644 lib/trie/leaf/type_test.go diff --git a/lib/trie/branch/type.go b/lib/trie/branch/type.go deleted file mode 100644 index c680652801b..00000000000 --- a/lib/trie/branch/type.go +++ /dev/null @@ -1,12 +0,0 @@ -package branch - -import "github.com/ChainSafe/gossamer/lib/trie/node" - -// Type returns node.BranchType if the branch value -// is nil, and node.BranchWithValueType otherwise. -func (b *Branch) Type() node.Type { - if b.Value == nil { - return node.BranchType - } - return node.BranchWithValueType -} diff --git a/lib/trie/branch/type_test.go b/lib/trie/branch/type_test.go deleted file mode 100644 index 0b49c6db86e..00000000000 --- a/lib/trie/branch/type_test.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2021 ChainSafe Systems (ON) -// SPDX-License-Identifier: LGPL-3.0-only - -package branch - -import ( - "testing" - - "github.com/ChainSafe/gossamer/lib/trie/node" - "github.com/stretchr/testify/assert" -) - -func Test_Branch_Type(t *testing.T) { - testCases := map[string]struct { - branch *Branch - Type node.Type - }{ - "nil value": { - branch: &Branch{}, - Type: node.BranchType, - }, - "empty value": { - branch: &Branch{ - Value: []byte{}, - }, - Type: node.BranchWithValueType, - }, - "non empty value": { - branch: &Branch{ - Value: []byte{1}, - }, - Type: node.BranchWithValueType, - }, - } - - for name, testCase := range testCases { - testCase := testCase - t.Run(name, func(t *testing.T) { - t.Parallel() - - Type := testCase.branch.Type() - - assert.Equal(t, testCase.Type, Type) - }) - } -} diff --git a/lib/trie/leaf/type.go b/lib/trie/leaf/type.go deleted file mode 100644 index d182f2dd225..00000000000 --- a/lib/trie/leaf/type.go +++ /dev/null @@ -1,8 +0,0 @@ -package leaf - -import "github.com/ChainSafe/gossamer/lib/trie/node" - -// Type returns node.LeafType. -func (l *Leaf) Type() node.Type { - return node.LeafType -} diff --git a/lib/trie/leaf/type_test.go b/lib/trie/leaf/type_test.go deleted file mode 100644 index f3713d88f8f..00000000000 --- a/lib/trie/leaf/type_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package leaf - -import ( - "testing" - - "github.com/ChainSafe/gossamer/lib/trie/node" - "github.com/stretchr/testify/assert" -) - -func Test_Leaf_Type(t *testing.T) { - t.Parallel() - - leaf := new(Leaf) - - Type := leaf.Type() - - assert.Equal(t, node.LeafType, Type) -}