Skip to content

Commit

Permalink
Allow custom allotment of account bound mana
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed May 8, 2024
1 parent f537f51 commit 3fbd3a5
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 41 deletions.
1 change: 1 addition & 0 deletions bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `Client::getOutputManaRewards()` slot query parameter;
- Allow custom allotment of account bound mana;

## 2.0.0-alpha.9 - 2024-05-02

Expand Down
1 change: 1 addition & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `Client::get_output_mana_rewards()` slot query parameter;
- Allow custom allotment of account bound mana;

## 2.0.0-alpha.1 - 2024-05-07

Expand Down
6 changes: 6 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 2.0.0-beta.1 - 2024-05-08

### Fixed

- Allow custom allotment of account bound mana;

## 2.0.0-alpha.1 - 2024-05-08

Initial alpha release of the 2.0 `cli-wallet`.
Expand Down
1 change: 1 addition & 0 deletions sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- `Client::get_output_mana_rewards()` slot query parameter;
- Allow custom allotment of account bound mana;

## 2.0.0-alpha.1 - 2024-04-29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ impl TransactionBuilder {
mana_gained += new_required_allotment.min(output.mana());
}
}
mana_gained = mana_gained.saturating_sub(output.mana());
} else if input.output.native_token().is_some() {
remainder_work_score += self.protocol_parameters.work_score(self.native_token_remainder())
} else if mana_gained > missing_mana {
Expand Down
139 changes: 99 additions & 40 deletions sdk/tests/client/transaction_builder/account_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,28 +1557,24 @@ fn two_accounts_required() {
assert!(unsorted_eq(&selected.inputs_data, &inputs));
assert_eq!(selected.transaction.outputs().len(), 3);
assert!(selected.transaction.outputs().contains(&outputs[0]));
assert!(
selected
.transaction
.outputs()
.iter()
.any(|output| if let Output::Account(output) = output {
output.account_id() == &account_id_1
} else {
false
})
);
assert!(
selected
.transaction
.outputs()
.iter()
.any(|output| if let Output::Account(output) = output {
output.account_id() == &account_id_2
} else {
false
})
)
assert!(selected
.transaction
.outputs()
.iter()
.any(|output| if let Output::Account(output) = output {
output.account_id() == &account_id_1
} else {
false
}));
assert!(selected
.transaction
.outputs()
.iter()
.any(|output| if let Output::Account(output) = output {
output.account_id() == &account_id_2
} else {
false
}))
}

#[test]
Expand Down Expand Up @@ -2372,9 +2368,10 @@ fn account_transition_with_required_context_inputs() {
))
.with_features([BlockIssuerFeature::new(
u32::MAX,
BlockIssuerKeys::from_vec(vec![
Ed25519PublicKeyHashBlockIssuerKey::new(**ed25519_address.as_ed25519()).into(),
])
BlockIssuerKeys::from_vec(vec![Ed25519PublicKeyHashBlockIssuerKey::new(
**ed25519_address.as_ed25519(),
)
.into()])
.unwrap(),
)
.unwrap()])
Expand All @@ -2390,12 +2387,10 @@ fn account_transition_with_required_context_inputs() {
})
.collect::<Vec<_>>();

let outputs = vec![
BasicOutputBuilder::new_with_amount(1_000_000)
.add_unlock_condition(AddressUnlockCondition::new(ed25519_address.clone()))
.finish_output()
.unwrap(),
];
let outputs = vec![BasicOutputBuilder::new_with_amount(1_000_000)
.add_unlock_condition(AddressUnlockCondition::new(ed25519_address.clone()))
.finish_output()
.unwrap()];

let selected = TransactionBuilder::new(
inputs.clone(),
Expand Down Expand Up @@ -2435,9 +2430,10 @@ fn send_amount_from_block_issuer_account_with_generated_mana() {
))
.with_features([BlockIssuerFeature::new(
u32::MAX,
BlockIssuerKeys::from_vec(vec![
Ed25519PublicKeyHashBlockIssuerKey::new(**ed25519_address.as_ed25519()).into(),
])
BlockIssuerKeys::from_vec(vec![Ed25519PublicKeyHashBlockIssuerKey::new(
**ed25519_address.as_ed25519(),
)
.into()])
.unwrap(),
)
.unwrap()])
Expand All @@ -2452,12 +2448,10 @@ fn send_amount_from_block_issuer_account_with_generated_mana() {
})
.collect::<Vec<_>>();

let outputs = vec![
BasicOutputBuilder::new_with_amount(1_000_000)
.add_unlock_condition(AddressUnlockCondition::new(ed25519_address.clone()))
.finish_output()
.unwrap(),
];
let outputs = vec![BasicOutputBuilder::new_with_amount(1_000_000)
.add_unlock_condition(AddressUnlockCondition::new(ed25519_address.clone()))
.finish_output()
.unwrap()];

let selected = TransactionBuilder::new(
inputs.clone(),
Expand All @@ -2484,3 +2478,68 @@ fn send_amount_from_block_issuer_account_with_generated_mana() {
1
);
}

#[test]
fn custom_allot_account_bound_mana() {
let protocol_parameters = iota_mainnet_protocol_parameters().clone();
let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap();
let ed25519_address = Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap();

let provided_allotment = 500_000;
let account_mana = 2_000_000;

let inputs = [AccountOutputBuilder::new_with_amount(2_000_000, account_id_1)
.with_mana(account_mana)
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.add_feature(
BlockIssuerFeature::new(
u32::MAX,
BlockIssuerKeys::from_vec(vec![Ed25519PublicKeyHashBlockIssuerKey::new(
**ed25519_address.as_ed25519(),
)
.into()])
.unwrap(),
)
.unwrap(),
)
.finish_output()
.unwrap()];
let inputs = inputs
.into_iter()
.map(|input| InputSigningData {
output: input,
output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SLOT_INDEX)),
chain: None,
})
.collect::<Vec<_>>();

let outputs = [];

let selected = TransactionBuilder::new(
inputs.clone(),
outputs.clone(),
[Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()],
SLOT_INDEX,
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2)
.with_mana_allotments(Some((account_id_1, provided_allotment)))
.finish()
.unwrap();

assert!(unsorted_eq(&selected.inputs_data, &inputs));
assert_eq!(selected.transaction.outputs().len(), 1);

assert_eq!(selected.transaction.allotments().len(), 1);
assert_eq!(
selected.transaction.allotments()[0],
ManaAllotment::new(account_id_1, provided_allotment).unwrap()
);
assert_eq!(
selected.transaction.outputs().iter().map(|o| o.mana()).sum::<u64>(),
account_mana - provided_allotment
);
}

0 comments on commit 3fbd3a5

Please sign in to comment.