Skip to content

Commit 8a85747

Browse files
authored
Merge pull request #19 from blooo-io/feat/LDG-158-implement-mint-method-and-tests
Feat/ldg 158 implement mint method and tests
2 parents 568f298 + 8c72e37 commit 8a85747

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+113
-8
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ APP_LOAD_PARAMS += --appFlags 0x800 --path "44'/60'" --path "45'" --path "44'/1'
2525
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)
2626

2727
APPVERSION_M = 1
28-
APPVERSION_N = 4
28+
APPVERSION_N = 5
2929
APPVERSION_P = 0
3030
APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
3131

Diff for: README.md

+4-1

Diff for: src/contract.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "ledger_nft_plugin.h"
22

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

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

35+
// Function: mint (MultiMint1155)
36+
// Selector: 0x08dc9f42
37+
static const uint8_t MINT_V2_SELECTOR[SELECTOR_SIZE] = {0x08, 0xdc, 0x9f, 0x42};
38+
3539
// Plugin uses 0x00000 as a dummy address to reprecent ETH.
3640
const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3741
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -47,6 +51,7 @@ const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS] = {
4751
MINT_SIGN_V2_SELECTOR,
4852
BID_SELECTOR,
4953
FINALIZE_AUCTION_SELECTOR,
54+
MINT_V2_SELECTOR,
5055
};
5156

5257
static const uint8_t MULTI_MINT_CONTRACT_NFT_ADDRESS[ADDRESS_LENGTH] = {

Diff for: src/handle_finalize.c

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ void handle_finalize(void *parameters) {
1616
case BID:
1717
msg->numScreens = 2;
1818
break;
19+
case MINT_V2:
20+
msg->numScreens = 3;
21+
break;
1922
case MINT_SIGN_V2:
2023
msg->numScreens = 4;
2124
break;

Diff for: src/handle_init_contract.c

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ void handle_init_contract(void *parameters) {
4646
case FINALIZE_AUCTION:
4747
context->next_param = AUCTION_ID;
4848
break;
49+
case MINT_V2:
50+
context->next_param = TOKEN_ID;
51+
break;
4952
default:
5053
PRINTF("Missing selectorIndex: %d\n", context->selectorIndex);
5154
msg->result = ETH_PLUGIN_RESULT_ERROR;

Diff for: src/handle_provide_parameter.c

+23
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ void handle_auction(ethPluginProvideParameter_t *msg, context_t *context) {
8181
}
8282
}
8383

84+
void handle_mint_v2(ethPluginProvideParameter_t *msg, context_t *context) {
85+
switch (context->next_param) {
86+
case TOKEN_ID:
87+
// Using context->token_id to store the auctionId
88+
handle_token_id(msg, context);
89+
context->next_param = AMOUNT;
90+
break;
91+
case AMOUNT:
92+
handle_amount(msg, context);
93+
context->next_param = NONE;
94+
break;
95+
case NONE:
96+
break;
97+
default:
98+
PRINTF("Param not supported\n");
99+
msg->result = ETH_PLUGIN_RESULT_ERROR;
100+
break;
101+
}
102+
}
103+
84104
void handle_provide_parameter(void *parameters) {
85105
ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters;
86106
context_t *context = (context_t *) msg->pluginContext;
@@ -115,6 +135,9 @@ void handle_provide_parameter(void *parameters) {
115135
case FINALIZE_AUCTION:
116136
handle_auction(msg, context);
117137
break;
138+
case MINT_V2:
139+
handle_mint_v2(msg, context);
140+
break;
118141
default:
119142
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
120143
msg->result = ETH_PLUGIN_RESULT_ERROR;

Diff for: src/handle_query_contract_id.c

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ void handle_query_contract_id(void *parameters) {
4444
case FINALIZE_AUCTION:
4545
strlcpy(msg->version, "Finalize Auction", msg->versionLength);
4646
break;
47+
case MINT_V2:
48+
strlcpy(msg->version, "MultiMint1155 - Mint", msg->versionLength);
49+
break;
4750
default:
4851
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
4952
msg->result = ETH_PLUGIN_RESULT_ERROR;

Diff for: src/handle_query_contract_ui.c

+12
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ static screens_t get_screen(const ethQueryContractUI_t *msg,
9696
return ERROR;
9797
}
9898
break;
99+
case MINT_V2:
100+
switch (index) {
101+
case 0:
102+
return TOKEN_ID_SCREEN;
103+
case 1:
104+
return AMOUNT_SCREEN;
105+
case 2:
106+
return PAYABLE_AMOUNT_SCREEN;
107+
default:
108+
return ERROR;
109+
}
110+
break;
99111
default:
100112
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
101113
return ERROR;

Diff for: src/ledger_nft_plugin.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "eth_internals.h"
55
#include "eth_plugin_interface.h"
66

7-
#define NUM_SELECTORS 8
7+
#define NUM_SELECTORS 9
88
#define NUM_CONTRACTS 4
99
#define PLUGIN_NAME "Ledger NFT"
1010
#define TOKEN_FOUND 1 << 1
@@ -25,6 +25,7 @@ typedef enum {
2525
MINT_SIGN_V2,
2626
BID,
2727
FINALIZE_AUCTION,
28+
MINT_V2,
2829
} selector_t;
2930

3031
// Enumeration used to parse the smart contract data.

Diff for: tests/networks/ethereum_goerli/ledgerNFT/b2c.json

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
"erc20OfInterest": [],
5252
"method": "mintSign",
5353
"plugin": "LedgerNFT"
54+
},
55+
"0x08dc9f42": {
56+
"erc20OfInterest": [],
57+
"method": "mint",
58+
"plugin": "LedgerNFT"
5459
}
5560
}
5661
},
413 Bytes
287 Bytes
287 Bytes
308 Bytes
374 Bytes
358 Bytes
414 Bytes
349 Bytes
463 Bytes
329 Bytes
325 Bytes
463 Bytes
329 Bytes
325 Bytes
364 Bytes
414 Bytes
364 Bytes
417 Bytes
472 Bytes
382 Bytes
414 Bytes
417 Bytes
472 Bytes
382 Bytes

Diff for: tests/src/mintMM1155.test.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { processTest, populateTransaction } from "./test.fixture";
2+
3+
const contractName = "MultiMintContractNFT";
4+
5+
const testLabel = "MintMM1155"; // <= Name of the test
6+
const testDirSuffix = "mint_mm1155"; // <= directory to compare device snapshots to
7+
const signedPlugin = false;
8+
const testNetwork = "ethereum_goerli";
9+
10+
const contractAddr = "0x12b180053db389b6200e6f646949e6ab7b385d40";
11+
const chainID = 1;
12+
13+
// Selector: 0x08dc9f42
14+
// [0] 0000000000000000000000000000000000000000000000000000000000000015 tokenId
15+
// [1] 0000000000000000000000000000000000000000000000000000000000000002 amount
16+
// [2] 0000000000000000000000000000000000000000000000000000000000000060 offset to data
17+
// [3] 0000000000000000000000000000000000000000000000000000000000000008 data length
18+
// [4] 746573745f6e6674000000000000000000000000000000000000000000000000 data
19+
20+
const inputData = "0x08dc9f420000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000008746573745f6e6674000000000000000000000000000000000000000000000000";
21+
const value = "12.0";
22+
23+
// Create serializedTx and remove the "0x" prefix
24+
const serializedTx = populateTransaction(contractAddr, inputData, chainID, value);
25+
26+
const devices = [
27+
{
28+
name: "nanos",
29+
label: "Nano S",
30+
steps: 6, // <= Define the number of steps for this test case and this device
31+
},
32+
{
33+
name: "nanox",
34+
label: "Nano X",
35+
steps: 6, // <= Define the number of steps for this test case and this device
36+
},
37+
{
38+
name: "nanosp",
39+
label: "Nano S+",
40+
steps: 6, // <= Define the number of steps for this test case and this device
41+
},
42+
43+
];
44+
45+
devices.forEach((device) => {
46+
processTest(device, contractName, testLabel, testDirSuffix, "", signedPlugin, serializedTx, testNetwork);
47+
});

Diff for: tests/src/mint.test.js renamed to tests/src/mintMMNFT.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { processTest, populateTransaction } from "./test.fixture";
22

33
const contractName = "MultiMintContractNFT";
44

5-
const testLabel = "Mint"; // <= Name of the test
6-
const testDirSuffix = "mint"; // <= directory to compare device snapshots to
5+
const testLabel = "MintMMNFT"; // <= Name of the test
6+
const testDirSuffix = "mint_mmnft"; // <= directory to compare device snapshots to
77
const signedPlugin = false;
88
const testNetwork = "ethereum_goerli";
99

Diff for: tests/src/mintV2.test.js renamed to tests/src/mintSMM721.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { processTest, populateTransaction } from "./test.fixture";
22

33
const contractName = "StableMultiMintERC721";
44

5-
const testLabel = "mintV2"; // <= Name of the test
6-
const testDirSuffix = "mint_v2"; // <= directory to compare device snapshots to
5+
const testLabel = "mintSMM721"; // <= Name of the test
6+
const testDirSuffix = "mint_smm721"; // <= directory to compare device snapshots to
77
const signedPlugin = false;
88
const testNetwork = "ethereum_goerli";
99

0 commit comments

Comments
 (0)