forked from xyield/xrpl-go
-
Notifications
You must be signed in to change notification settings - Fork 18
[TA-4884] Support NFTokenMintOffer #142
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b7806ee
feat(xrpl): add Amount, Expiration, and Destination fields with valid…
banasa44 b2942b7
feat(xrpl): add NFTokenMintMetadata struct and implement TxMeta inter…
banasa44 71942fb
chore(changelog): Add NFTokenMintOffer support
banasa44 e3798a2
Merge branch 'v0.1.x' into xrpl/feat/nftoken-mint-offer
banasa44 1a9e1d7
Merge branch 'v0.1.x' into xrpl/feat/nftoken-mint-offer
banasa44 8fdde23
feat(xrpl): enhance NFTokenMint validation tests for Amount and Desti…
banasa44 02ee0ba
refactor(xrpl): remove unnecessary expiration amount validation in NF…
banasa44 a67020b
refactor(xrpl): remove unnecessary tests
banasa44 da353e6
feat(xrpl): add TransferFee and Expiration types
banasa44 d08d725
feat(xrpl): refactor move NFTokenMintMetadata into a separate file, r…
banasa44 7a07d86
fix(xrpl): remove invalid test
banasa44 d3d57dc
refactor(xrpl): change TransferFee and Expiration types to primitive …
banasa44 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package transaction | ||
|
|
||
| import ( | ||
| "github.com/Peersyst/xrpl-go/xrpl/transaction/types" | ||
| ) | ||
|
|
||
| type NFTokenMintMetadata struct { | ||
| TxObjMeta | ||
| // rippled 1.11.0 or later | ||
| NFTokenID *types.NFTokenID `json:"nftoken_id,omitempty"` | ||
| // if Amount is present | ||
| OfferID *types.Hash256 `json:"offer_id,omitempty"` | ||
| } | ||
|
|
||
| func (NFTokenMintMetadata) TxMeta() {} |
GuillemGarciaDev marked this conversation as resolved.
Show resolved
Hide resolved
GuillemGarciaDev marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package transaction | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/Peersyst/xrpl-go/xrpl/transaction/types" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestNFTokenMintMetadata_JSONMarshal(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| metadata *NFTokenMintMetadata | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "pass - with both NFTokenID and OfferID", | ||
| metadata: &NFTokenMintMetadata{ | ||
| NFTokenID: func() *types.NFTokenID { | ||
| id := types.NFTokenID("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65") | ||
| return &id | ||
| }(), | ||
| OfferID: func() *types.Hash256 { | ||
| hash := types.Hash256("68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77") | ||
| return &hash | ||
| }(), | ||
| }, | ||
| expected: `{"nftoken_id":"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65","offer_id":"68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77"}`, | ||
| }, | ||
| { | ||
| name: "pass - empty metadata", | ||
| metadata: &NFTokenMintMetadata{}, | ||
| expected: `{}`, | ||
| }, | ||
| { | ||
| name: "pass - with full metadata including TxObjMeta", | ||
| metadata: &NFTokenMintMetadata{ | ||
| TxObjMeta: TxObjMeta{ | ||
| TransactionIndex: 123, | ||
| TransactionResult: "tesSUCCESS", | ||
| }, | ||
| NFTokenID: func() *types.NFTokenID { | ||
| id := types.NFTokenID("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65") | ||
| return &id | ||
| }(), | ||
| OfferID: func() *types.Hash256 { | ||
| hash := types.Hash256("68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77") | ||
| return &hash | ||
| }(), | ||
| }, | ||
| expected: `{"TransactionIndex":123,"TransactionResult":"tesSUCCESS","nftoken_id":"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65","offer_id":"68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77"}`, | ||
| }, | ||
| { | ||
| name: "pass - nil pointers should omit fields", | ||
| metadata: &NFTokenMintMetadata{ | ||
| NFTokenID: nil, | ||
| OfferID: nil, | ||
| }, | ||
| expected: `{}`, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| jsonBytes, err := json.Marshal(tt.metadata) | ||
| require.NoError(t, err) | ||
| assert.JSONEq(t, tt.expected, string(jsonBytes)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestNFTokenMintMetadata_JSONUnmarshal(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| json string | ||
| expected *NFTokenMintMetadata | ||
| }{ | ||
| { | ||
| name: "pass - with both NFTokenID and OfferID", | ||
| json: `{"nftoken_id":"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65","offer_id":"68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77"}`, | ||
| expected: &NFTokenMintMetadata{ | ||
| NFTokenID: func() *types.NFTokenID { | ||
| id := types.NFTokenID("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65") | ||
| return &id | ||
| }(), | ||
| OfferID: func() *types.Hash256 { | ||
| hash := types.Hash256("68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77") | ||
| return &hash | ||
| }(), | ||
| }, | ||
| }, | ||
| { | ||
| name: "pass - empty metadata", | ||
| json: `{}`, | ||
| expected: &NFTokenMintMetadata{}, | ||
| }, | ||
| { | ||
| name: "pass - with full metadata including TxObjMeta fields", | ||
| json: `{"TransactionIndex":123,"TransactionResult":"tesSUCCESS","nftoken_id":"000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65","offer_id":"68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77"}`, | ||
| expected: &NFTokenMintMetadata{ | ||
| TxObjMeta: TxObjMeta{ | ||
| TransactionIndex: 123, | ||
| TransactionResult: "tesSUCCESS", | ||
| }, | ||
| NFTokenID: func() *types.NFTokenID { | ||
| id := types.NFTokenID("000B013A95F14B0044F78A264E41713C64B5F89242540EE208C3098E00000D65") | ||
| return &id | ||
| }(), | ||
| OfferID: func() *types.Hash256 { | ||
| hash := types.Hash256("68CD1F6F906494EA08C9CB5CAFA64DFA90D4E834B7151899B73231DE5A0C3B77") | ||
| return &hash | ||
| }(), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| var metadata NFTokenMintMetadata | ||
| err := json.Unmarshal([]byte(tt.json), &metadata) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.expected, &metadata) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.