Skip to content

Commit

Permalink
Merge pull request #1432 from hyperledger/optional-name
Browse files Browse the repository at this point in the history
Add name/version if not specified
  • Loading branch information
nguyer authored Dec 13, 2023
2 parents 04d0357 + 6406eef commit 4645f28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
6 changes: 6 additions & 0 deletions internal/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,12 @@ func (cm *contractManager) checkParamSchema(ctx context.Context, name string, in

func (cm *contractManager) GenerateFFI(ctx context.Context, generationRequest *fftypes.FFIGenerationRequest) (*fftypes.FFI, error) {
generationRequest.Namespace = cm.namespace
if generationRequest.Name == "" {
generationRequest.Name = "generated"
}
if generationRequest.Version == "" {
generationRequest.Version = "0.0.1"
}
ffi, err := cm.blockchain.GenerateFFI(ctx, generationRequest)
if err == nil {
err = cm.ResolveFFI(ctx, ffi)
Expand Down
28 changes: 17 additions & 11 deletions internal/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3553,22 +3553,28 @@ func TestAddJSONSchemaExtension(t *testing.T) {
func TestGenerateFFI(t *testing.T) {
cm := newTestContractManager()
mbi := cm.blockchain.(*blockchainmocks.Plugin)
mbi.On("GenerateFFI", mock.Anything, mock.Anything).Return(&fftypes.FFI{
Name: "generated",
Version: "1.0",
Methods: []*fftypes.FFIMethod{
{
Name: "method1",
},
{
Name: "method1",
gfi := mbi.On("GenerateFFI", mock.Anything, mock.Anything)
gfi.Run(func(args mock.Arguments) {
gf := args[1].(*fftypes.FFIGenerationRequest)
gfi.Return(&fftypes.FFI{
Name: gf.Name,
Version: gf.Version,
Methods: []*fftypes.FFIMethod{
{
Name: "method1",
},
{
Name: "method1",
},
},
},
}, nil)
}, nil)
})

ffi, err := cm.GenerateFFI(context.Background(), &fftypes.FFIGenerationRequest{})
assert.NoError(t, err)
assert.NotNil(t, ffi)
assert.Equal(t, "generated", ffi.Name)
assert.Equal(t, "0.0.1", ffi.Version)
assert.Equal(t, "method1", ffi.Methods[0].Name)
assert.Equal(t, "method1", ffi.Methods[0].Pathname)
assert.Equal(t, "method1", ffi.Methods[1].Name)
Expand Down

0 comments on commit 4645f28

Please sign in to comment.