Skip to content

Commit

Permalink
Call ResolveFFI from GenerateFFI
Browse files Browse the repository at this point in the history
Ensures that the generated FFI is valid and has pathnames for each method.

Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Nov 8, 2023
1 parent 854df6c commit 8759f8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,11 @@ 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
return cm.blockchain.GenerateFFI(ctx, generationRequest)
ffi, err := cm.blockchain.GenerateFFI(ctx, generationRequest)
if err == nil {
err = cm.ResolveFFI(ctx, ffi)
}
return ffi, err
}

func (cm *contractManager) getDefaultContractListenerOptions() *core.ContractListenerOptions {
Expand Down
15 changes: 14 additions & 1 deletion internal/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3554,12 +3554,25 @@ func TestGenerateFFI(t *testing.T) {
cm := newTestContractManager()
mbi := cm.blockchain.(*blockchainmocks.Plugin)
mbi.On("GenerateFFI", mock.Anything, mock.Anything).Return(&fftypes.FFI{
Name: "generated",
Name: "generated",
Version: "1.0",
Methods: []*fftypes.FFIMethod{
{
Name: "method1",
},
{
Name: "method1",
},
},
}, 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, "method1", ffi.Methods[0].Name)
assert.Equal(t, "method1", ffi.Methods[0].Pathname)
assert.Equal(t, "method1", ffi.Methods[1].Name)
assert.Equal(t, "method1_1", ffi.Methods[1].Pathname)
}

type MockFFIParamValidator struct{}
Expand Down

0 comments on commit 8759f8c

Please sign in to comment.