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

Feat/ldg 158 implement mint method and tests #19

Merged
merged 5 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ APP_LOAD_PARAMS += --appFlags 0x800 --path "44'/60'" --path "45'" --path "44'/1'
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPVERSION_M = 1
APPVERSION_N = 4
APPVERSION_N = 5
APPVERSION_P = 0
APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ On these smart contracts, the functions covered by this plugin are:
|StableMultiMintERC721 |stableMintSign | 0x11413601| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|StableMultiMintERC721 |stableMint | 0x804b936f| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|StableMultiMintERC721 |mintSign | 0xf39247a9| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|StableMultiMintERC721 |mint (v2) | 0xa0712d68| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|StableMultiMintERC721 |mint | 0xa0712d68| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|MultiMint1155 | mintSign (v2) | 0x657bb113| <table><tbody> <tr><td><code>uint256 tokenId</code></td></tr> <tr><td><code>uint256 amount</code></td></tr> <tr><td><code>address pass</code></td></tr></tbody></table> |
|AuctionCore |bid | 0x454a2ab3| <table><tbody> <tr><td><code>uint256 auctionId</code></td></tr> </tbody></table> |
|AuctionCore |finalizeAuction| 0xe8083863| <table><tbody> <tr><td><code>uint256 auctionId</code></td></tr> </tbody></table> |
|MultiMint1155 | mint (v2) | 0x08dc9f42| <table><tbody> <tr><td><code>uint256 tokenId</code></td></tr> <tr><td><code>uint256 amount</code></td></tr></tbody></table> |

> **Note:** Only the third `mint` function is labelled as v2 because the first two share the same selector and behave identically.

## Build

Expand Down
7 changes: 6 additions & 1 deletion src/contract.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ledger_nft_plugin.h"

// Function: mint
// Function: mint (MultiMintContractNFT, StableMultiMintERC721)
// Selector: 0xa0712d68
static const uint8_t MINT_SELECTOR[SELECTOR_SIZE] = {0xa0, 0x71, 0x2d, 0x68};

Expand Down Expand Up @@ -32,6 +32,10 @@ static const uint8_t BID_SELECTOR[SELECTOR_SIZE] = {0x45, 0x4a, 0x2a, 0xb3};
// Selector: 0xe8083863
static const uint8_t FINALIZE_AUCTION_SELECTOR[SELECTOR_SIZE] = {0xe8, 0x08, 0x38, 0x63};

// Function: mint (MultiMint1155)
// Selector: 0x08dc9f42
static const uint8_t MINT_V2_SELECTOR[SELECTOR_SIZE] = {0x08, 0xdc, 0x9f, 0x42};

// Plugin uses 0x00000 as a dummy address to reprecent ETH.
const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -47,6 +51,7 @@ const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS] = {
MINT_SIGN_V2_SELECTOR,
BID_SELECTOR,
FINALIZE_AUCTION_SELECTOR,
MINT_V2_SELECTOR,
};

static const uint8_t MULTI_MINT_CONTRACT_NFT_ADDRESS[ADDRESS_LENGTH] = {
Expand Down
3 changes: 3 additions & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ void handle_finalize(void *parameters) {
case BID:
msg->numScreens = 2;
break;
case MINT_V2:
msg->numScreens = 3;
break;
case MINT_SIGN_V2:
msg->numScreens = 4;
break;
Expand Down
3 changes: 3 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void handle_init_contract(void *parameters) {
case FINALIZE_AUCTION:
context->next_param = AUCTION_ID;
break;
case MINT_V2:
context->next_param = TOKEN_ID;
break;
default:
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
23 changes: 23 additions & 0 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ void handle_auction(ethPluginProvideParameter_t *msg, context_t *context) {
}
}

void handle_mint_v2(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case TOKEN_ID:
// Using context->token_id to store the auctionId
handle_token_id(msg, context);
context->next_param = AMOUNT;
break;
case AMOUNT:
handle_amount(msg, context);
context->next_param = NONE;
break;
case NONE:
break;
default:
PRINTF("Param not supported\n");
msg->result = ETH_PLUGIN_RESULT_ERROR;
break;
}
}

void handle_provide_parameter(void *parameters) {
ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters;
context_t *context = (context_t *) msg->pluginContext;
Expand Down Expand Up @@ -115,6 +135,9 @@ void handle_provide_parameter(void *parameters) {
case FINALIZE_AUCTION:
handle_auction(msg, context);
break;
case MINT_V2:
handle_mint_v2(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void handle_query_contract_id(void *parameters) {
case FINALIZE_AUCTION:
strlcpy(msg->version, "Finalize Auction", msg->versionLength);
break;
case MINT_V2:
strlcpy(msg->version, "MultiMint1155 - Mint", msg->versionLength);
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
12 changes: 12 additions & 0 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ static screens_t get_screen(const ethQueryContractUI_t *msg,
return ERROR;
}
break;
case MINT_V2:
switch (index) {
case 0:
return TOKEN_ID_SCREEN;
case 1:
return AMOUNT_SCREEN;
case 2:
return PAYABLE_AMOUNT_SCREEN;
default:
return ERROR;
}
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
return ERROR;
Expand Down
3 changes: 2 additions & 1 deletion src/ledger_nft_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "eth_internals.h"
#include "eth_plugin_interface.h"

#define NUM_SELECTORS 8
#define NUM_SELECTORS 9
#define NUM_CONTRACTS 4
#define PLUGIN_NAME "Ledger NFT"
#define TOKEN_FOUND 1 << 1
Expand All @@ -25,6 +25,7 @@ typedef enum {
MINT_SIGN_V2,
BID,
FINALIZE_AUCTION,
MINT_V2,
} selector_t;

// Enumeration used to parse the smart contract data.
Expand Down
5 changes: 5 additions & 0 deletions tests/networks/ethereum_goerli/ledgerNFT/b2c.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"erc20OfInterest": [],
"method": "mintSign",
"plugin": "LedgerNFT"
},
"0x08dc9f42": {
"erc20OfInterest": [],
"method": "mint",
"plugin": "LedgerNFT"
}
}
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions tests/src/mintMM1155.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { processTest, populateTransaction } from "./test.fixture";

const contractName = "MultiMintContractNFT";

const testLabel = "MintMM1155"; // <= Name of the test
const testDirSuffix = "mint_mm1155"; // <= directory to compare device snapshots to
const signedPlugin = false;
const testNetwork = "ethereum_goerli";

const contractAddr = "0x12b180053db389b6200e6f646949e6ab7b385d40";
const chainID = 1;

// Selector: 0x08dc9f42
// [0] 0000000000000000000000000000000000000000000000000000000000000015 tokenId
// [1] 0000000000000000000000000000000000000000000000000000000000000002 amount
// [2] 0000000000000000000000000000000000000000000000000000000000000060 offset to data
// [3] 0000000000000000000000000000000000000000000000000000000000000008 data length
// [4] 746573745f6e6674000000000000000000000000000000000000000000000000 data

const inputData = "0x08dc9f420000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000008746573745f6e6674000000000000000000000000000000000000000000000000";
const value = "12.0";

// Create serializedTx and remove the "0x" prefix
const serializedTx = populateTransaction(contractAddr, inputData, chainID, value);

const devices = [
{
name: "nanos",
label: "Nano S",
steps: 6, // <= Define the number of steps for this test case and this device
},
{
name: "nanox",
label: "Nano X",
steps: 6, // <= Define the number of steps for this test case and this device
},
{
name: "nanosp",
label: "Nano S+",
steps: 6, // <= Define the number of steps for this test case and this device
},

];

devices.forEach((device) => {
processTest(device, contractName, testLabel, testDirSuffix, "", signedPlugin, serializedTx, testNetwork);
});
4 changes: 2 additions & 2 deletions tests/src/mint.test.js → tests/src/mintMMNFT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { processTest, populateTransaction } from "./test.fixture";

const contractName = "MultiMintContractNFT";

const testLabel = "Mint"; // <= Name of the test
const testDirSuffix = "mint"; // <= directory to compare device snapshots to
const testLabel = "MintMMNFT"; // <= Name of the test
const testDirSuffix = "mint_mmnft"; // <= directory to compare device snapshots to
const signedPlugin = false;
const testNetwork = "ethereum_goerli";

Expand Down
4 changes: 2 additions & 2 deletions tests/src/mintV2.test.js → tests/src/mintSMM721.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { processTest, populateTransaction } from "./test.fixture";

const contractName = "StableMultiMintERC721";

const testLabel = "mintV2"; // <= Name of the test
const testDirSuffix = "mint_v2"; // <= directory to compare device snapshots to
const testLabel = "mintSMM721"; // <= Name of the test
const testDirSuffix = "mint_smm721"; // <= directory to compare device snapshots to
const signedPlugin = false;
const testNetwork = "ethereum_goerli";

Expand Down