Skip to content

Commit

Permalink
fix(wallet): use correct type for contract_id in the contract constit…
Browse files Browse the repository at this point in the history
…ution file format (#4179)

Description
---
Changed the type of the `contract_id` field in the file format from a `PublicKey` to a `String`, and then parsed it as hex into a `FixedHash` (which is the proper type).

Motivation and Context
---
When using a real `contract_id` value on contract constitution publishing, we got a file format parsing error

How Has This Been Tested?
---
Changed the `contract_id` field in the fixture file to a value that trigger the issue. The test now pass.
  • Loading branch information
mrnaveira authored Jun 10, 2022
1 parent 41570f6 commit 669a1bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::convert::{TryFrom, TryInto};

use serde::{Deserialize, Serialize};
use tari_common_types::types::PublicKey;
use tari_common_types::types::{FixedHash, PublicKey};
use tari_core::transactions::transaction_components::{
CheckpointParameters,
ConstitutionChangeFlags,
Expand All @@ -34,11 +34,11 @@ use tari_core::transactions::transaction_components::{
SideChainConsensus,
SideChainFeatures,
};
use tari_utilities::ByteArray;
use tari_utilities::hex::Hex;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ConstitutionDefinitionFileFormat {
pub contract_id: PublicKey,
pub contract_id: String,
pub validator_committee: Vec<PublicKey>,
pub consensus: SideChainConsensus,
pub initial_reward: u64,
Expand Down Expand Up @@ -66,7 +66,7 @@ impl TryFrom<ConstitutionDefinitionFileFormat> for SideChainFeatures {
type Error = String;

fn try_from(value: ConstitutionDefinitionFileFormat) -> Result<Self, Self::Error> {
let contract_id = value.contract_id.as_bytes().try_into().map_err(|e| format!("{}", e))?;
let contract_id = FixedHash::from_hex(&value.contract_id).map_err(|e| format!("{}", e))?;

Ok(Self::builder(contract_id)
.with_contract_constitution(value.try_into()?)
Expand Down
8 changes: 7 additions & 1 deletion integration_tests/features/support/validator_node_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ Then(
Given(
"I have a validator node {word} connected to base node {word} and wallet {word} with {word} set to {word}",
{ timeout: 20 * 1000 },
async function (vn_name, base_node_name, wallet_name, option_key, option_value) {
async function (
vn_name,
base_node_name,
wallet_name,
option_key,
option_value
) {
const baseNode = this.getNode(base_node_name);
const walletNode = this.getWallet(wallet_name);

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/fixtures/contract_constitution.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"contract_id": "ccac168b8edd67b10d152d1ed2337efc65da9fc0b6256dd49b3c559032553d44",
"contract_id": "90b1da4524ea0e9479040d906db9194d8af90f28d05ff2d64c0a82eb93125177",
"validator_committee": [
"ccac168b8edd67b10d152d1ed2337efc65da9fc0b6256dd49b3c559032553d44",
"ccac168b8edd67b10d152d1ed2337efc65da9fc0b6256dd49b3c559032553d44",
Expand Down

0 comments on commit 669a1bd

Please sign in to comment.