Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Problem (Fix #949): deposit amount fee calculation is not correct #1118

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions chain-abci/src/enclave_bridge/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ pub fn handle_enc_dec(_req: &RequestQuery, resp: &mut ResponseQuery, _storage: &
resp.code = 1;
}

fn pad_payload(payload: &[u8]) -> Vec<u8> {
// https://tools.ietf.org/html/rfc8452
let mut result = Vec::with_capacity(payload.len() + 16);
result.extend_from_slice(payload);
result.extend_from_slice(&[0; 16]);
result
}

/// temporary mock
#[cfg(feature = "mock-enc-dec")]
pub fn handle_enc_dec(_req: &RequestQuery, resp: &mut ResponseQuery, storage: &Storage) {
Expand All @@ -53,7 +61,7 @@ pub fn handle_enc_dec(_req: &RequestQuery, resp: &mut ResponseQuery, storage: &S
key_from: 0,
txid: tx.id(),
init_vector: [0u8; 12],
txpayload: plain.encode(),
txpayload: pad_payload(&plain.encode()),
},
}),
};
Expand All @@ -68,7 +76,7 @@ pub fn handle_enc_dec(_req: &RequestQuery, resp: &mut ResponseQuery, storage: &S
key_from: 0,
txid: maintx.id(),
init_vector: [0u8; 12],
txpayload: plain.encode(),
txpayload: pad_payload(&plain.encode()),
},
}),
};
Expand All @@ -84,7 +92,7 @@ pub fn handle_enc_dec(_req: &RequestQuery, resp: &mut ResponseQuery, storage: &S
key_from: 0,
txid: tx.id(),
init_vector: [0u8; 12],
txpayload: plain.encode(),
txpayload: pad_payload(&plain.encode()),
},
}),
};
Expand Down
10 changes: 4 additions & 6 deletions client-core/src/signer/dummy_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ pub struct DummySigner();
impl DummySigner {
/// pad payload to the multiples of 128bits
fn pad_payload(&self, plain_txaux: PlainTxAux) -> Vec<u8> {
let unit = 16_usize;
let plain_payload_len = plain_txaux.encode().len();
// PKCS7 padding -- if the len is multiple of the block length, it'll still be padded
vec![0; plain_payload_len + unit - plain_payload_len % unit]
// https://tools.ietf.org/html/rfc8452
vec![0; plain_txaux.encode().len() + 16]
}

/// Creates a mock merkletree
Expand Down Expand Up @@ -81,9 +79,9 @@ impl DummySigner {
TxAux::EnclaveTx(tx_enclave_aux)
}

/// Mock the txaux for withdraw transactions
/// Mock the txaux for deposit transactions
pub fn mock_txaux_for_deposit(&self, input_len: usize) -> Result<TxAux> {
let total_pubkeys_len = 2;
let total_pubkeys_len = 1;
let witness = self.schnorr_sign_inputs_len(total_pubkeys_len, input_len)?;
let plain_payload = PlainTxAux::DepositStakeTx(witness);
let padded_payload = self.pad_payload(plain_payload);
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/multinode/join_cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"mnemonic": "must sunny destroy cousin ladder survey wrong employ illness thing divert under ready purpose elegant",
"validator_seed": "9f06b6bb885d0143092aad7a6df2f1cae7690fcbfa1edb8727542372085ade8b",
"node_seed": "208ff2032ea90646cecee2b21de3488593f8c3a0b9c78ab02bfbf9aa15ab35b4",
"bonded_coin": 100000000000000000,
"bonded_coin": 100000000010000000,
"unbonded_coin": 0,
"base_port": 26650
},
Expand Down Expand Up @@ -39,12 +39,12 @@
{
"op": "replace",
"path": "/initial_fee_policy/base_fee",
"value": "0.0"
"value": "1.1"
},
{
"op": "replace",
"path": "/initial_fee_policy/per_byte_fee",
"value": "0.0"
"value": "1.25"
}
],
"tendermint_config_patch": [
Expand Down
10 changes: 9 additions & 1 deletion integration-tests/multinode/join_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@

print('Withdraw unbonded', bonded_staking)
transfer = rpc.address.list(enckey=enckey, type='transfer')[0]
txid = rpc.staking.withdraw_all_unbonded(bonded_staking, transfer, enckey=enckey)
txid = rpc.staking.withdraw_all_unbonded(
bonded_staking, transfer, enckey=enckey,
# test fee calculation
view_keys=[
rpc.wallet.view_key(enckey=enckey),
# view key of node1
RPC(BASE_PORT+10).wallet.view_key(enckey=enckey),
]
)

print('Wait for transaction', txid)
wait_for_tx(rpc, txid)
Expand Down
16 changes: 16 additions & 0 deletions integration-tests/pytests/test_small.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from chainrpc import RPC
from .common import wait_for_tx

rpc = RPC()


@pytest.mark.withfee
def test_deposit_amount(addresses):
'execute a deposit amount to self, check staking state change'
bonded1 = int(rpc.staking.state(addresses.unbonded_staking)['bonded'])
txid = rpc.staking.deposit_amount(addresses.unbonded_staking, 100000000)
wait_for_tx(rpc, txid)
rpc.wallet.sync()
bonded2 = int(rpc.staking.state(addresses.unbonded_staking)['bonded'])
assert bonded1 + 100000000 == bonded2
2 changes: 1 addition & 1 deletion integration-tests/zero_fee_cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"node_seed": "95356c3c5791cdd1601087c6448aa2a3b1f6f01ecce89b601194e0d6f27fdd7b",
"bonded_coin": 500000000000000000,
"unbonded_coin": 500000000000000000,
"base_port": 16650
"base_port": 26650
}
],
"chain_config_patch": [
Expand Down