-
Notifications
You must be signed in to change notification settings - Fork 18
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
Exploit new support in firefly-signer
and firefly-common
for large & scientific JSON numbers
#153
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3319256
Add test for new firefly-signer support for large and scientific numbers
matthew1001 126b710
Unmarshal to fftypes.JSONAny, not interface
matthew1001 16d9f21
Pull in latest ffcommon and ffsigner
matthew1001 bad89ec
Remove scientific number test - not supporting at present
matthew1001 40ef535
Pull in ffcommon, reinstate scientific numbers
matthew1001 20dfcbb
Update to the latest releases of ffcommon, ffsigner, fftm
matthew1001 bc3d2d3
Update unit test
matthew1001 26bfeae
Update prepare_transaction
matthew1001 3d18e2f
Add unit tests for TX prepare
matthew1001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package ethereum | |
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/fftypes" | ||
|
@@ -39,19 +40,91 @@ const samplePrepareDeployTX = `{ | |
"gas": 1000000, | ||
"nonce": "111", | ||
"value": "12345678901234567890123456789", | ||
"contract": "0xfeedbeef", | ||
"contract": "0xdeadbeef", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤣 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah a slightly cheeky way to ensure the asserts in the tests don't match on the contract bytes when checking for integers that match |
||
"definition": [{ | ||
"inputs": [ | ||
{ | ||
"internalType":" uint256", | ||
"name": "x", | ||
"type": "uint256" | ||
} | ||
}, | ||
{ | ||
"internalType":" address", | ||
"name": "y", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType":" string", | ||
"name": "z", | ||
"type": "string" | ||
} | ||
EnriqueL8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
"outputs":[], | ||
"type":"constructor" | ||
}], | ||
"params": [ 4276993775 ] | ||
"params": [ 4276993775, "0x5f906824E562B6a0F278D910D388728b833a43bB", "some-text" ] | ||
}` | ||
|
||
const samplePrepareDeployTXLargeInputParams = `{ | ||
"ffcapi": { | ||
"version": "v1.0.0", | ||
"id": "904F177C-C790-4B01-BDF4-F2B4E52E607E", | ||
"type": "DeployContract" | ||
}, | ||
"from": "0xb480F96c0a3d6E9e9a263e4665a39bFa6c4d01E8", | ||
"to": "0xe1a078b9e2b145d0a7387f09277c6ae1d9470771", | ||
"gas": 1000000, | ||
"nonce": "111", | ||
"value": "12345678901234567890123456789", | ||
"contract": "0xdeadbeef", | ||
"definition": [{ | ||
"inputs": [ | ||
{ | ||
"internalType":" uint256", | ||
"name": "x", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType":" string", | ||
"name": "y", | ||
"type": "string" | ||
} | ||
], | ||
"outputs":[], | ||
"type":"constructor" | ||
}], | ||
"params": [ 10000000000000000000000001, "some-text" ] | ||
}` | ||
|
||
const samplePrepareDeployTXScientificNotation = `{ | ||
"ffcapi": { | ||
"version": "v1.0.0", | ||
"id": "904F177C-C790-4B01-BDF4-F2B4E52E607E", | ||
"type": "DeployContract" | ||
}, | ||
"from": "0xb480F96c0a3d6E9e9a263e4665a39bFa6c4d01E8", | ||
"to": "0xe1a078b9e2b145d0a7387f09277c6ae1d9470771", | ||
"gas": 1000000, | ||
"nonce": "111", | ||
"value": "12345678901234567890123456789", | ||
"contract": "0xdeadbeef", | ||
"definition": [{ | ||
"inputs": [ | ||
{ | ||
"internalType":" uint256", | ||
"name": "x", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType":" string", | ||
"name": "y", | ||
"type": "string" | ||
} | ||
], | ||
"outputs":[], | ||
"type":"constructor" | ||
}], | ||
"params": [ 1.0000000000000000000000001e+25, "some-text" ] | ||
}` | ||
|
||
func TestDeployContractPrepareOkNoEstimate(t *testing.T) { | ||
|
@@ -63,12 +136,53 @@ func TestDeployContractPrepareOkNoEstimate(t *testing.T) { | |
err := json.Unmarshal([]byte(samplePrepareDeployTX), &req) | ||
assert.NoError(t, err) | ||
res, reason, err := c.DeployContractPrepare(ctx, &req) | ||
|
||
assert.NoError(t, err) | ||
assert.Empty(t, reason) | ||
assert.Equal(t, int64(1000000), res.Gas.Int64()) | ||
|
||
// Basic check that our input param 4276993775 is in the TX data | ||
assert.True(t, strings.Contains(res.TransactionData, "feedbeef")) | ||
// Basic check that our input param "some-text" is in the TX data | ||
assert.True(t, strings.Contains(res.TransactionData, strings.ToLower("736f6d652d74657874"))) | ||
// Basic check that our input param address is in the TX data | ||
assert.True(t, strings.Contains(res.TransactionData, strings.ToLower("5f906824E562B6a0F278D910D388728b833a43bB"))) | ||
} | ||
|
||
func TestDeployContractPrepareOkLargeInputParam(t *testing.T) { | ||
|
||
ctx, c, _, done := newTestConnector(t) | ||
defer done() | ||
|
||
var req ffcapi.ContractDeployPrepareRequest | ||
err := json.Unmarshal([]byte(samplePrepareDeployTXLargeInputParams), &req) | ||
assert.NoError(t, err) | ||
res, reason, err := c.DeployContractPrepare(ctx, &req) | ||
assert.NoError(t, err) | ||
assert.Empty(t, reason) | ||
assert.Equal(t, int64(1000000), res.Gas.Int64()) | ||
|
||
// Basic check that our input param 10000000000000000000000001 is in the TX data | ||
assert.True(t, strings.Contains(res.TransactionData, "84595161401484a000001")) | ||
// Basic check that our input param "some-text" is in the TX data | ||
assert.True(t, strings.Contains(res.TransactionData, "736f6d652d74657874")) | ||
} | ||
|
||
func TestDeployContractPrepareOkScientificNotationParam(t *testing.T) { | ||
|
||
ctx, c, _, done := newTestConnector(t) | ||
defer done() | ||
|
||
var req ffcapi.ContractDeployPrepareRequest | ||
err := json.Unmarshal([]byte(samplePrepareDeployTXScientificNotation), &req) | ||
assert.NoError(t, err) | ||
res, reason, err := c.DeployContractPrepare(ctx, &req) | ||
assert.NoError(t, err) | ||
assert.Empty(t, reason) | ||
assert.Equal(t, int64(1000000), res.Gas.Int64()) | ||
// Basic check that our input param 1.0000000000000000000000001e+25 is in the TX data | ||
assert.True(t, strings.Contains(res.TransactionData, "84595161401484a000001")) | ||
// Basic check that our input param "some-text" is in the TX data | ||
assert.True(t, strings.Contains(res.TransactionData, "736f6d652d74657874")) | ||
} | ||
|
||
func TestDeployContractPrepareWithEstimateRevert(t *testing.T) { | ||
|
@@ -209,7 +323,7 @@ func TestDeployContractPrepareBadParamType(t *testing.T) { | |
|
||
var req ffcapi.ContractDeployPrepareRequest | ||
err := json.Unmarshal([]byte(samplePrepareDeployTX), &req) | ||
req.Params = []*fftypes.JSONAny{fftypes.JSONAnyPtr(`"!wrong"`)} | ||
req.Params = []*fftypes.JSONAny{fftypes.JSONAnyPtr(`"!wrong"`), fftypes.JSONAnyPtr(`"0x90eB678C3586103805a676d21721Cc6883a6c3AE"`), fftypes.JSONAnyPtr(`"helloworld"`)} | ||
assert.NoError(t, err) | ||
_, reason, err := c.DeployContractPrepare(ctx, &req) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For context: The type of
p
is*fftypes.JSONAny
which has implemented an Unmarshal method