Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deepanshutr/chore #435

Merged
merged 58 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7d23bc6
fix(query_request_test):Refactor query tests to use key instead of IDs
deepanshutr Mar 7, 2024
9532d8a
chore: removing test cases generate with dated test case building met…
deepanshutr Mar 7, 2024
c5317e4
feat(utilities):Add GenerateUniqueIdentifierList function in id.go
deepanshutr Mar 8, 2024
7810636
feat(helpers):adding collection codec and auxiliary tests
deepanshutr Mar 8, 2024
b60f26a
Merge branch 'master' of github.com:AssetMantle/modules into deepansh…
deepanshutr Mar 12, 2024
fd2a0ea
feat(helpers):adding invariants test
deepanshutr Mar 13, 2024
ec288dd
refactor(test_constants): retiring usage of TestClientContext
deepanshutr Mar 13, 2024
9ada41f
fix(validatable_parameter): adding nic checks
deepanshutr Mar 13, 2024
bc0f951
feat(validatable_parameter): adding unit test cases
deepanshutr Mar 13, 2024
9cb2c94
fix(auxiliaries): adding nil checks
deepanshutr Mar 14, 2024
16a3fb4
fix(auxiliary): adding nil checks
deepanshutr Mar 14, 2024
e0a7255
chore(helpers): Update tests and add error handling to auxiliary module
deepanshutr Mar 14, 2024
f79a53f
feat(message): adding GetFromAddress method to message interface
deepanshutr Mar 18, 2024
6bf2be8
feat(transaction_keeper): using getFromAddress method
deepanshutr Mar 18, 2024
9411e31
fix(transaction_keeper_test):Update import paths and enhance helper f…
deepanshutr Mar 19, 2024
1244f96
refactor(transaction_keeper_test):optimizing test case
deepanshutr Mar 22, 2024
026086b
refactor(parameter_manager): return self on set.
deepanshutr Mar 25, 2024
b7e6012
refactor(wrap): performance optimization
deepanshutr Mar 25, 2024
1e3345c
test(wrap): code optimization
deepanshutr Mar 25, 2024
4a4efb5
feat(assets): adding max list length validation
deepanshutr Mar 25, 2024
9f2a984
feat(wrap): optimizing code execution
deepanshutr Mar 26, 2024
56f5693
feat(wrap): adding test cases
deepanshutr Mar 26, 2024
f4b6997
minor code optimization
deepanshutr Mar 26, 2024
266e0f2
chore(unwrap): code optimization
deepanshutr Mar 26, 2024
8314812
feat(unwrap): adding transaction keeper test case
deepanshutr Mar 26, 2024
4f416b4
chore(unwrap): adding code comments
deepanshutr Mar 27, 2024
52193bc
chore(send): adding test cases
deepanshutr Mar 27, 2024
fa66ea6
chore(send): optimizing keeper code execution and adding code documen…
deepanshutr Mar 28, 2024
727e4b5
test(send): adding test cases
deepanshutr Mar 28, 2024
6452660
test(send): request test optimization
deepanshutr Mar 28, 2024
145778e
feat(send): adding getValueAsInt helper method to message
deepanshutr Mar 28, 2024
175a86e
feat(supplement): making auxiliary response public for testing
deepanshutr Mar 28, 2024
6e38656
refactor(property_list): retiring prototype() method
deepanshutr Apr 3, 2024
189fe52
refactor(wrap):Refactor error messages in ValidateBasic function
deepanshutr Apr 5, 2024
1f0da68
test(wrap):Add advanced test cases for ValidateBasic method
deepanshutr Apr 5, 2024
3263633
refactor(wrap):Refactor error messages in ValidateBasic function
deepanshutr Apr 5, 2024
0611c7c
test(wrap):Add advanced test cases for ValidateBasic method
deepanshutr Apr 5, 2024
30f190c
refactor(send):Refactor error messages in ValidateBasic function
deepanshutr Apr 5, 2024
bc08883
test(send):Add comprehensive tests for Message validation
deepanshutr Apr 5, 2024
697ad21
refactor(assets):Refactor error handling in message validation
deepanshutr Apr 5, 2024
3864de6
refactor(errors):Refactor error names from "IncorrectMessage" to "Inv…
deepanshutr Apr 5, 2024
1c1731e
chore(split/utilities): removing unnecessary checks,
deepanshutr Apr 12, 2024
03f6a22
fix(split/mappable): adding nil checks
deepanshutr Apr 12, 2024
e3c4347
chore(splits/send): minor code optimization
deepanshutr Apr 12, 2024
185f278
fix(splits/transfer):Update validation in transfer auxiliaryRequest
deepanshutr Apr 12, 2024
fee1545
refactor(splits/transfer): minor code optimizations
deepanshutr Apr 12, 2024
fef5214
test(splits/transfer): removing old test cases
deepanshutr Apr 12, 2024
5e180ef
test(splits/transfer): improving test coverage for keeper
deepanshutr Apr 12, 2024
3a88281
test(identities/authenticate): improving test coverage for keeper
deepanshutr Apr 12, 2024
a99b339
Refactor validation in mint auxiliary request
deepanshutr Apr 12, 2024
fef95cf
Remove auxiliaryRequestFromInterface test
deepanshutr Apr 12, 2024
d459f70
Update auxiliary tests in mint module
deepanshutr Apr 12, 2024
d6d14e3
Improve validation and error handling in mint module
deepanshutr Apr 12, 2024
f32fc84
minor code cleanup
deepanshutr Apr 12, 2024
44b61e6
Removed obsolete auxiliaryRequestFromInterface test
deepanshutr Apr 12, 2024
ac6d5e6
Refactor validation in auxiliaryRequest
deepanshutr Apr 12, 2024
adac516
Refactor auxiliaryRequest validation and tests
deepanshutr Apr 12, 2024
5fdd1dd
Enhance validation for auxiliary request
deepanshutr Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion helpers/base/auxiliaries.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright [2021] - [2022], AssetMantle Pte. Ltd. and the code contributors

Check failure on line 1 in helpers/base/auxiliaries.go

View workflow job for this annotation

GitHub Actions / golangci-lint

: # github.com/AssetMantle/modules/helpers/base [github.com/AssetMantle/modules/helpers/base.test]
// SPDX-License-Identifier: Apache-2.0

package base

import "github.com/AssetMantle/modules/helpers"
import (
"github.com/AssetMantle/modules/helpers"
)

type auxiliaries struct {
auxiliaryList []helpers.Auxiliary
Expand All @@ -25,6 +27,19 @@
}

func NewAuxiliaries(auxiliaryList ...helpers.Auxiliary) helpers.Auxiliaries {
for i, auxiliary := range auxiliaryList {

if auxiliary == nil {
panic("nil auxiliary")
}

for j, checkAuxiliary := range auxiliaryList {
if i != j && auxiliary.GetName() == checkAuxiliary.GetName() {
panic("repeated auxiliary")
}
}
}

return auxiliaries{
auxiliaryList: auxiliaryList,
}
Expand Down
193 changes: 193 additions & 0 deletions helpers/base/auxiliaries_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package base

import (
"github.com/AssetMantle/modules/helpers"
"github.com/AssetMantle/modules/utilities/random"
"github.com/stretchr/testify/assert"
"testing"
)

var (
randomUniqueIdentifiers = random.GenerateUniqueIdentifierList("", 2)
)

type mockAuxiliary struct {
name string
}

func (m mockAuxiliary) GetName() string {
return m.name
}

func (m mockAuxiliary) GetKeeper() helpers.AuxiliaryKeeper {
// Stubbed return as it is not used in GetAuxiliary
return nil
}

func (m mockAuxiliary) Initialize(helpers.Mapper, helpers.ParameterManager, ...interface{}) helpers.Auxiliary {
// Stubbed return as it is not used in GetAuxiliary
return nil
}

func TestGetAuxiliary(t *testing.T) {
tests := []struct {
name string
auxiliaries auxiliaries
arg string
want helpers.Auxiliary
}{
{
name: "Empty AuxiliaryList",
auxiliaries: auxiliaries{},
arg: "auxiliary1",
want: nil,
},
{
name: "Nil Return Non-Existing Name",
auxiliaries: auxiliaries{auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[1]}}},
arg: "nonexistent",
want: nil,
},
{
name: "Flyweight1",
auxiliaries: auxiliaries{auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[1]}}},
arg: randomUniqueIdentifiers[0],
want: mockAuxiliary{randomUniqueIdentifiers[0]},
},
{
name: "Flyweight2",
auxiliaries: auxiliaries{auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[1]}}},
arg: randomUniqueIdentifiers[1],
want: mockAuxiliary{randomUniqueIdentifiers[1]},
},
{
name: "Unordered Flyweight1",
auxiliaries: auxiliaries{auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[1]}, mockAuxiliary{randomUniqueIdentifiers[0]}}},
arg: randomUniqueIdentifiers[0],
want: mockAuxiliary{randomUniqueIdentifiers[0]},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.auxiliaries.GetAuxiliary(tt.arg); got != tt.want {
t.Errorf("GetAuxiliary() = %v, want %v", got, tt.want)
}
})
}
}

func Test_auxiliaries_Get(t *testing.T) {
type fields struct {
auxiliaryList []helpers.Auxiliary
}
tests := []struct {
name string
fields fields
want []helpers.Auxiliary
}{
{
name: "Empty AuxiliaryList",
fields: fields{
auxiliaryList: []helpers.Auxiliary{},
},
want: []helpers.Auxiliary{},
},
{
name: "Non-empty AuxiliaryList",
fields: fields{
auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[1]}},
},
want: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[1]}},
},
{
name: "Nil Auxiliary",
fields: fields{
auxiliaryList: []helpers.Auxiliary{nil},
},
want: []helpers.Auxiliary{nil},
},
{
name: "Nil Auxiliary in list",
fields: fields{
auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, nil, mockAuxiliary{randomUniqueIdentifiers[1]}},
},
want: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, nil, mockAuxiliary{randomUniqueIdentifiers[1]}},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
auxiliaries := auxiliaries{
auxiliaryList: tt.fields.auxiliaryList,
}
assert.Equalf(t, tt.want, auxiliaries.Get(), "Get()")
})
}
}

func TestNewAuxiliaries(t *testing.T) {
type args struct {
auxiliaryList []helpers.Auxiliary
}
tests := []struct {
name string
args args
want helpers.Auxiliaries
panic bool
}{
{
name: "Empty AuxiliaryList",
args: args{
auxiliaryList: []helpers.Auxiliary{},
},
want: auxiliaries{
auxiliaryList: []helpers.Auxiliary{},
},
},
{
name: "Non-empty AuxiliaryList",
args: args{
auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[1]}},
},
want: auxiliaries{
auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[1]}},
},
},
{
name: "Nil Auxiliary",
args: args{
auxiliaryList: []helpers.Auxiliary{nil},
},
panic: true,
},
{
name: "Nil Auxiliary in list",
args: args{
auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, nil, mockAuxiliary{randomUniqueIdentifiers[1]}},
},
panic: true,
},
{
name: "Repeated Auxiliary",
args: args{
auxiliaryList: []helpers.Auxiliary{mockAuxiliary{randomUniqueIdentifiers[0]}, mockAuxiliary{randomUniqueIdentifiers[0]}},
},
panic: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
auxListInterface := make([]interface{}, len(tt.args.auxiliaryList))
for i, v := range tt.args.auxiliaryList {
auxListInterface[i] = v
}
if tt.panic {
assert.Panicsf(t, func() { NewAuxiliaries(tt.args.auxiliaryList...) }, "NewAuxiliaries(%v)", auxListInterface...)
return
} else {
assert.Equalf(t, tt.want, NewAuxiliaries(tt.args.auxiliaryList...), "NewAuxiliaries(%v)", auxListInterface...)
}
})
}
}
9 changes: 9 additions & 0 deletions helpers/base/auxiliary.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ func (auxiliary auxiliary) Initialize(mapper helpers.Mapper, parameterManager he
return auxiliary
}
func NewAuxiliary(name string, keeperPrototype func() helpers.AuxiliaryKeeper) helpers.Auxiliary {
if name == "" {
panic("empty name")
}

if keeperPrototype == nil {
panic("nil keeper prototype")

}

return auxiliary{
name: name,
keeperPrototype: keeperPrototype,
Expand Down
Loading
Loading