-
Notifications
You must be signed in to change notification settings - Fork 10
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
Implement the eth_call
JSON-RPC endpoint
#24
Conversation
c2b2d79
to
cb22df8
Compare
cb22df8
to
570218c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the client interface from go-sdk https://github.com/onflow/flow-go-sdk/blob/master/access/client.go#L34
that way you don't have to redefine the interface, and the mocks are also already available from go-sdk if you want to use for testing.
@sideninja Good call out 👍 I did update the code to use the func (_m *MockRPCClient) ExecuteScriptAtLatestBlock(ctx context.Context, in *access.ExecuteScriptAtLatestBlockRequest, opts ...grpc.CallOption) (*access.ExecuteScriptResponse, error) { vs what we want func (_m *MockAccessClient) ExecuteScriptAtLatestBlock(ctx context.Context, script []byte, arguments []cadence.Value) (cadence.Value, error) { I have generated a mock implementation of |
api/api.go
Outdated
import EVM from 0xf8d6e0586b0a20c7 | ||
|
||
access(all) | ||
fun main(data: [UInt8], contractAddress: [UInt8; 20]): [UInt8] { | ||
let flowAccount = getAuthAccount<auth(Storage) &Account>(Address(0xf8d6e0586b0a20c7)) | ||
let bridgedAccount = flowAccount.storage.borrow<&EVM.BridgedAccount>( | ||
from: /storage/evm | ||
) ?? panic("Could not borrow reference to the bridged account!") | ||
|
||
let evmResult = bridgedAccount.call( | ||
to: EVM.EVMAddress(bytes: contractAddress), | ||
data: data, | ||
gasLimit: 300000, | ||
value: EVM.Balance(flow: 0.0) | ||
) | ||
|
||
return evmResult | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would extract this into a call.cdc
file and then embed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point 👍
I have updated that in 86a9487 and added some TODOs for interpolating some parts of the script.
@@ -0,0 +1,813 @@ | |||
// Code generated by mockery v2.21.4. DO NOT EDIT. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this copied over or generated? if it was copied it's better if generated, just add a comment for generation on top of FlowAccessClient and use mockery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I even think it would be useful to create a PR against flow-go-sdk and generate the mock there for the interface:
https://github.com/onflow/flow-go-sdk/blob/master/access/client.go#L34
Then you could just use that mock and it would also help others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was generated with mockery, I have added a relevant Makefile recipe as well in: 1b20bb5.
I will also open up a PR to do this in flow-go-sdk, however, it might take some time to get that change in. So for the time being, we can stick to the mock generated in this repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok great. As long as it's being generated here it's all good, and the PR in go-sdk would be good to have but not a blocker yeah
api/mocks/mocks.go
Outdated
type FlowAccessClient interface { | ||
access.Client | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type FlowAccessClient interface { | |
access.Client | |
} | |
type FlowAccessClient access.Client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this does not work for mockery. I think it needs an interface definition to work, and not a type "alias".
I had a look at flow-go(onflow/flow-go@02e4142), and the Proxy interface is how they mock implementations for interfaces defined in 3rd party packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting.
Closes: #9
Description
Functionality to execute read-only function calls.
For contributor use:
master
branchFiles changed
in the Github PR explorer