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

testutils: Convert the workflow spec to and from proto in ensureGraph #1014

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

ferglor
Copy link
Collaborator

@ferglor ferglor commented Jan 28, 2025

In this PR, we're modifying the ensureGraph function within testutils' Runner to convert the workflow spec to a protobuf, and then back again, to get around an issue I encountered while developing a workflow

Specifically, I was using the read contract capability in my workflow, but when I ran my unit test against the workflow, I got this error:

invalid refs map[ConfidenceLevel:finalized Params:map[fundTokenId:0xd4b2f7c3e5f28c8d0a34b17b9ce5d6d7e85a9bcf1e6a7d8e3c2a5f9b8d4e6c3d]] for step read

I was using the capability like so:

chainRead := readcontract.Config{
			ContractAddress:      config.DataSourceContractAddress,
			ContractName:         config.DataSourceContractName,
			ContractReaderConfig: config.DataSourceContractConfig,
			ReadIdentifier:       fmt.Sprintf("%s-%s-%s", config.DataSourceContractAddress, config.DataSourceContractName, config.DataSourceContractFunction),
		}.New(
			w,
			"[email protected]",
			"read",
			readcontract.ActionInput{
				ConfidenceLevel: sdk.ConstantDefinition("finalized"),
				Params: sdk.ConstantDefinition(readcontract.InputParams{
					"fundTokenId": config.DataSourceFundTokenID,
					"_unused":     cron.Ref(), // TODO: Figure out a nicer way to do this.
				}),
			})

And mocking it like this:

contractRead := readcontractcaptest.Action(runner, "[email protected]", func(input readcontractcap.Input) (readcontractcap.Output, error) {
		b, err := json.Marshal(map[string]any{
			"nav":         "123",
			"fundTokenId": "0xd4b2f7c3e5f28c8d0a34b17b9ce5d6d7e85a9bcf1e6a7d8e3c2a5f9b8d4e6c3d",
		})

		if err != nil {
			return readcontractcap.Output{}, err
		}

		return readcontractcap.Output{
			LatestValue: b,
		}, nil
	})

It seems the issue I encountered is specific to local unit testing only; that is, if I was testing my code remotely I would not have encountered this.

Therefore, we're adding serializing and deserializing steps to the local test runner to bypass this issue

Copy link
Contributor

@justinkaseman justinkaseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change makes sense. Thanks for dealing with this.

@justinkaseman justinkaseman merged commit b32b200 into main Jan 28, 2025
10 of 11 checks passed
@justinkaseman justinkaseman deleted the feature/ensure-graph-fix branch January 28, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants