Skip to content

Commit

Permalink
Merge pull request #17 from blooo-io/feat/LDG-138-implement-finalizea…
Browse files Browse the repository at this point in the history
…uction-method-and-tests

Feat/ldg 138 implement finalizeauction method and tests
  • Loading branch information
Z4karia authored Mar 3, 2023
2 parents 0570670 + 4d8f0f2 commit 1dd1a08
Show file tree
Hide file tree
Showing 27 changed files with 71 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ static const uint8_t MINT_SIGN_V2_SELECTOR[SELECTOR_SIZE] = {0x65, 0x7b, 0xb1, 0
// Selector: 0x454a2ab3
static const uint8_t BID_SELECTOR[SELECTOR_SIZE] = {0x45, 0x4a, 0x2a, 0xb3};

// Function: finalizeAuction
// Selector: 0xe8083863
static const uint8_t FINALIZE_AUCTION_SELECTOR[SELECTOR_SIZE] = {0xe8, 0x08, 0x38, 0x63};

// 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,4 +51,5 @@ const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS] = {
MINT_V2_SELECTOR,
MINT_SIGN_V2_SELECTOR,
BID_SELECTOR,
FINALIZE_AUCTION_SELECTOR,
};
3 changes: 3 additions & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ void handle_finalize(void *parameters) {
context_t *context = (context_t *) msg->pluginContext;
msg->uiType = ETH_UI_TYPE_GENERIC;
switch (context->selectorIndex) {
case FINALIZE_AUCTION:
msg->numScreens = 1;
break;
case MINT:
case PRE_SALE_MINT:
case STABLE_MINT_SIGN:
Expand Down
1 change: 1 addition & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void handle_init_contract(void *parameters) {
context->next_param = OFFSET;
break;
case BID:
case FINALIZE_AUCTION:
context->next_param = AUCTION_ID;
break;
default:
Expand Down
5 changes: 3 additions & 2 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void handle_mint_sign_v2(ethPluginProvideParameter_t *msg, context_t *context) {
}
}

void handle_bid(ethPluginProvideParameter_t *msg, context_t *context) {
void handle_auction(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case AUCTION_ID:
// Using context->token_id to store the auctionId
Expand Down Expand Up @@ -113,7 +113,8 @@ void handle_provide_parameter(void *parameters) {
handle_mint_sign_v2(msg, context);
break;
case BID:
handle_bid(msg, context);
case FINALIZE_AUCTION:
handle_auction(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
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 @@ -31,6 +31,9 @@ void handle_query_contract_id(void *parameters) {
case BID:
strlcpy(msg->version, "Bid", msg->versionLength);
break;
case FINALIZE_AUCTION:
strlcpy(msg->version, "Finalize Auction", msg->versionLength);
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
9 changes: 9 additions & 0 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ static screens_t get_screen(const ethQueryContractUI_t *msg,
default:
return ERROR;
}
break;
case FINALIZE_AUCTION:
switch (index) {
case 0:
return AUCTION_ID_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 PLUGIN_NAME "Ledger NFT"
#define TOKEN_FOUND 1 << 1
#define SELECTOR_SIZE 4
Expand All @@ -24,6 +24,7 @@ typedef enum {
MINT_V2,
MINT_SIGN_V2,
BID,
FINALIZE_AUCTION,
} 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 @@ -62,6 +62,11 @@
"erc20OfInterest": [],
"method": "bid",
"plugin": "LedgerNFT"
},
"0xe8083863": {
"erc20OfInterest": [],
"method": "finalizeAuction",
"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.
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.
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.
40 changes: 40 additions & 0 deletions tests/src/finalizeAuction.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { processTest, populateTransaction } from "./test.fixture";

const contractName = "AuctionCore";

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

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

// [0] 000000000000000000000000000000000000000000000000000000000000007b auctionId
const inputData = "0xe8083863000000000000000000000000000000000000000000000000000000000000007b"

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

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

];

devices.forEach((device) => {
processTest(device, contractName, testLabel, testDirSuffix, "", signedPlugin, serializedTx, testNetwork);
});

0 comments on commit 1dd1a08

Please sign in to comment.