Skip to content

Commit

Permalink
Merge branch '2.0' into nova-wasm-explorer-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M authored Apr 22, 2024
2 parents 24c47e1 + 48126d2 commit ab3be64
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 138 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/bindings-nodejs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ jobs:
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV

- name: Install gon (macOS)
# Fork of https://github.com/mitchellh/gon
# https://github.com/Bearer/gon
# Since we're dealing with code signing secrets we want to pin the version of gon
if: ${{ startsWith(matrix.os, 'macos') }}
# https://github.com/mitchellh/gon
run: brew install mitchellh/gon/gon
run: |
wget https://raw.githubusercontent.com/Bearer/homebrew-tap/366bc999e14a8d04e07e24f9387bcbaf89c1bc53/Formula/gon.rb
brew install --formula gon.rb
rm gon.rb
- name: Set deployment target (macOS)
if: matrix.os == 'macos-13'
Expand Down Expand Up @@ -258,3 +263,4 @@ jobs:
body: https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/CHANGELOG.md
files: bindings/nodejs/prebuilds/@iota/*
tag_name: ${{ steps.prepare_release.outputs.tag_name }}
target_commitish: ${{ github.sha }}
1 change: 1 addition & 0 deletions .github/workflows/bindings-python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ jobs:
body: https://github.com/iotaledger/iota-sdk/blob/develop/bindings/python/CHANGELOG.md
files: wheels/*
tag_name: ${{ steps.tagname.outputs.TAG_NAME }}
target_commitish: ${{ github.sha }}

- uses: actions/setup-python@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/bindings-wasm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
shell: sh
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: yarn publish --access public
run: yarn publish --access public --tag alpha

- name: Prepare Github release
id: prepare_release
Expand All @@ -62,3 +62,4 @@ jobs:
body: "https://github.com/iotaledger/iota-sdk/blob/develop/bindings/wasm/CHANGELOG.md \n https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/CHANGELOG.md"
files: bindings/wasm/*.tgz
tag_name: ${{ steps.prepare_release.outputs.tag_name }}
target_commitish: ${{ github.sha }}
13 changes: 13 additions & 0 deletions bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 2.0.0-alpha.7 - 2024-04-19

### Fixed

- Mana allotment when burning something/setting a TransactionCapabilityFlag;
- Stronghold backup/restore;

## 2.0.0-alpha.6 - 2024-04-17

### Fixed

- MacOS binary build;

## 2.0.0-alpha.5 - 2024-04-15

### Added
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/gon-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"source": ["./build/Release/index.node"],
"bundle_id": "org.iota.sdk-nodejs",
"apple_id": {
"password": "@env:AC_PASSWORD"
"provider": "UG77RJKZHH"
},
"sign": {
"application_identity": "Developer ID Application: IOTA Stiftung (UG77RJKZHH)"
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iota/sdk",
"version": "2.0.0-alpha.5",
"version": "2.0.0-alpha.7",
"description": "Node.js binding to the IOTA SDK library",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions bindings/nodejs/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { spawnSync } = require('child_process');
const { status } = spawnSync(process.platform === 'win32' ? 'yarn.cmd' : 'yarn', ['build'], {
stdio: 'inherit',
cwd: resolve(__dirname, '../'),
shell: true
});

if (status === null) {
Expand Down
4 changes: 4 additions & 0 deletions bindings/wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 2.0.0-alpha.3 - 2024-04-19

Same changes as https://github.com/iotaledger/iota-sdk/blob/2.0/bindings/nodejs/CHANGELOG.md.

## 2.0.0-alpha.2 - 2024-04-02

Same changes as https://github.com/iotaledger/iota-sdk/blob/2.0/bindings/nodejs/CHANGELOG.md.
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iota/sdk-wasm",
"version": "2.0.0-alpha.2",
"version": "2.0.0-alpha.3",
"description": "WebAssembly bindings for the IOTA SDK library",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl TransactionBuilder {
.iter()
.map(|(&account_id, &mana)| ManaAllotment { account_id, mana }),
)
.with_capabilities(self.transaction_capabilities.clone())
.finish_with_params(&self.protocol_parameters)?;

let signed_transaction = SignedTransactionPayload::new(transaction, self.null_transaction_unlocks()?)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ impl<S: 'static + SecretManagerConfig> Wallet<S> {
}

// Store the wallet address
stronghold
.set(WALLET_ADDRESS_KEY, self.address().await.as_ref())
.await?;
stronghold.set(WALLET_ADDRESS_KEY, &self.address().await).await?;

// Store the wallet bip path
stronghold.set(WALLET_BIP_PATH_KEY, &self.bip_path().await).await?;

// Store the wallet alias
stronghold.set(WALLET_ALIAS_KEY, &self.alias().await).await?;
if let Some(alias) = self.alias().await {
stronghold.set(WALLET_ALIAS_KEY, &alias).await?;
}

let serialized_wallet_ledger = serde_json::to_value(&WalletLedgerDto::from(&*self.ledger.read().await))?;
stronghold.set(WALLET_LEDGER_KEY, &serialized_wallet_ledger).await?;
Expand All @@ -71,6 +71,7 @@ pub(crate) async fn read_fields_from_stronghold_snapshot<S: 'static + SecretMana
),
WalletError,
> {
log::debug!("[read_fields_from_stronghold_snapshot]");
migrate(stronghold).await?;

// Get client_options
Expand Down
109 changes: 106 additions & 3 deletions sdk/tests/client/transaction_builder/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@ use std::{
str::FromStr,
};

use crypto::keys::bip44::Bip44;
use iota_sdk::{
client::{
api::transaction_builder::{Burn, Requirement, TransactionBuilder, TransactionBuilderError},
secret::types::InputSigningData,
api::{
transaction_builder::{Burn, Requirement, TransactionBuilder, TransactionBuilderError},
GetAddressesOptions,
},
constants::SHIMMER_COIN_TYPE,
secret::{types::InputSigningData, SecretManage, SecretManager},
Client,
},
types::block::{
address::Address,
core::basic::StrongParents,
output::{
unlock_condition::AddressUnlockCondition, AccountId, AccountOutputBuilder, BasicOutputBuilder, ChainId,
NftId, SimpleTokenScheme, TokenId,
},
payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag},
payload::{
signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag},
Payload, SignedTransactionPayload,
},
protocol::iota_mainnet_protocol_parameters,
rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id},
slot::SlotIndex,
BlockBody, BlockId,
},
};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -771,6 +782,98 @@ fn burn_nfts_present() {
assert!(unsorted_eq(selected.transaction.outputs(), &outputs));
}

#[tokio::test]
async fn burn_nft_correct_mana_allotment() {
let secret_manager = SecretManager::try_from_mnemonic(Client::generate_mnemonic().unwrap()).unwrap();

let ed25519_address = secret_manager
.generate_ed25519_addresses(GetAddressesOptions::default().with_range(0..1))
.await
.unwrap()[0]
.clone()
.into_inner();

let protocol_parameters = iota_mainnet_protocol_parameters();
let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap();
let nft_id_1 = NftId::from_str(NFT_ID_1).unwrap();
let reference_mana_cost = 1;

let inputs = build_inputs(
[(
Nft {
amount: 1_000_000,
mana: 1_000_000,
nft_id: nft_id_1,
address: ed25519_address.clone(),
sender: None,
issuer: None,
sdruc: None,
expiration: None,
},
Some(Bip44::new(SHIMMER_COIN_TYPE)),
)],
Some(SLOT_INDEX),
);

let selected = TransactionBuilder::new(
inputs.clone(),
[],
[ed25519_address],
SLOT_INDEX,
SLOT_COMMITMENT_ID,
protocol_parameters.clone(),
)
.with_burn(Burn::new().set_nfts(HashSet::from([nft_id_1])))
.with_min_mana_allotment(account_id_1, reference_mana_cost)
.finish()
.unwrap();

assert_eq!(
selected.transaction.capabilities(),
&TransactionCapabilities::from([TransactionCapabilityFlag::DestroyNftOutputs])
);
assert!(unsorted_eq(&selected.inputs_data, &inputs));

let inputs = selected
.inputs_data
.iter()
.map(|input| (input.output_id(), &input.output))
.collect::<Vec<_>>();

iota_sdk::types::block::semantic::SemanticValidationContext::new(
&selected.transaction,
&inputs,
None,
None,
&protocol_parameters,
)
.validate()
.unwrap();

assert_eq!(selected.transaction.outputs().len(), 1);

let unlocks = secret_manager
.transaction_unlocks(&selected, &protocol_parameters)
.await
.unwrap();

let signed_transaction_payload = SignedTransactionPayload::new(selected.transaction.clone(), unlocks).unwrap();

let basic_block_body = BlockBody::build_basic(
StrongParents::from_vec(vec![BlockId::new([0; 36])]).unwrap(),
(protocol_parameters.work_score_parameters(), reference_mana_cost),
)
.with_payload(Payload::from(signed_transaction_payload))
.finish()
.unwrap();

assert_eq!(selected.transaction.allotments().len(), 1);
assert_eq!(
selected.transaction.allotments().first().unwrap().mana(),
basic_block_body.max_burned_mana(),
);
}

#[test]
fn burn_nft_in_outputs() {
let protocol_parameters = iota_mainnet_protocol_parameters().clone();
Expand Down
Loading

0 comments on commit ab3be64

Please sign in to comment.