Skip to content

Commit

Permalink
Merge #1892 #1895
Browse files Browse the repository at this point in the history
1892: Withdrawals as part of core and API transactions r=KtorZ a=KtorZ

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->

#1881 

# Overview

<!-- Detail in a few bullet points the work accomplished in this PR -->

- 589609e
  📍 **factor out common code in database migration**
  Turns out that adding column is a pretty common and straighfordward migration. I originally intended to add a new column to the TxMeta table, hence the refactor. In the end, I've used a different table for withdrawals, but the refactor is still worth it as it is IMO.

- e9e516c
  📍 **add withdrawals to API & core transaction data types**
  Still to be done: withdrawals must be discovered when processing blocks

- ff58489
  📍 **upgrade Byron & Jormungandr compatibility code with empty withdrawals**
  Withdrawals are only a thing in Shelley, so for this targets, we can safely replace them by empty lists

- 533b787
  📍 **wire withdrawals in Shelley compatibility code**
  Here, we extract withdrawals directly from the TxBody, the conversion is straightforward

- e2e6fbb
  📍 **include withdrawals where relevant in test and arbitrary generators**
  
- 4b6eaba
  📍 **add withdrawals to the API Swagger specification**
  We represent them as a list and not a key:value map with stake address as key because clients typically don't know the stake address associated with their wallet, so it'd be quite impractical for them to access this data if returned as a map...



# Comments

<!-- Additional comments or screenshots to attach if any -->

⚠️ Sorry, the PR spans over many files because I needed to add a new class constraints `DecodeStakeAddress` which goes side-by-side with the current `DecodeAddress`.

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


1895: hydra: Prevent caching of shelley integration test failures r=KtorZ a=rvl

### Issue Number

Not sure.

### Overview

This change causes integration tests to be re-run whenever the git revision changes, even if everything else is identical. Since these tests tend to fail a lot, we don't want to cache false failures.

Also increase the minimum severity for integration test logging, because debug level produces quite a lot of output.


Co-authored-by: KtorZ <[email protected]>
Co-authored-by: IOHK <[email protected]>
Co-authored-by: Rodney Lorrimar <[email protected]>
  • Loading branch information
4 people authored Jul 10, 2020
3 parents 210f392 + ab7bb2b + b90ee76 commit a844464
Show file tree
Hide file tree
Showing 54 changed files with 806 additions and 271 deletions.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let
haskellPackages = import ./nix/haskell.nix {
inherit config lib stdenv pkgs buildPackages;
inherit (pkgs) haskell-nix;
inherit src pr;
inherit src pr gitrev;
};

filterCardanoPackages = lib.filterAttrs (_: package: isCardanoWallet package);
Expand Down
18 changes: 17 additions & 1 deletion lib/byron/src/Cardano/Wallet/Byron/Compatibility.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
Expand Down Expand Up @@ -86,7 +87,11 @@ import Cardano.Crypto
import Cardano.Crypto.ProtocolMagic
( ProtocolMagicId, unProtocolMagicId )
import Cardano.Wallet.Api.Types
( DecodeAddress (..), EncodeAddress (..) )
( DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, EncodeStakeAddress (..)
)
import Cardano.Wallet.Primitive.AddressDerivation
( NetworkDiscriminant (..) )
import Cardano.Wallet.Primitive.AddressDerivation.Byron
Expand Down Expand Up @@ -354,6 +359,9 @@ fromTxAux txAux = case taTx txAux of

, outputs =
fromTxOut <$> NE.toList outputs

, withdrawals =
mempty
}

fromTxIn :: TxIn -> W.TxIn
Expand Down Expand Up @@ -494,6 +502,14 @@ fromProtocolMagicId = W.ProtocolMagic . fromIntegral . unProtocolMagicId
Address Encoding / Decoding
-------------------------------------------------------------------------------}

instance EncodeStakeAddress n where
encodeStakeAddress = error
"encodeStakeAddress: there's no such thing as stake address in Byron"

instance DecodeStakeAddress n where
decodeStakeAddress = error
"decodeStakeAddress: there's no such thing as stake address in Byron"

instance EncodeAddress 'Mainnet where
encodeAddress =
gEncodeAddress
Expand Down
5 changes: 3 additions & 2 deletions lib/byron/src/Cardano/Wallet/Byron/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ newTransactionLayer _proxy protocolMagic = TransactionLayer
witnesses <- forM (CS.inputs cs) $ \(_, TxOut addr _) ->
mkWitness protocolMagic sigData <$> lookupPrivateKey addr
pure
( Tx (Hash sigData) (second coin <$> CS.inputs cs) (CS.outputs cs)
( Tx (Hash sigData) (second coin <$> CS.inputs cs) (CS.outputs cs) mempty
, SealedTx $ CBOR.toStrictByteString $ CBOR.encodeSignedTx tx witnesses
)
where
Expand Down Expand Up @@ -190,6 +190,7 @@ newTransactionLayer _proxy protocolMagic = TransactionLayer
-- FIXME Do not require Tx to have resolvedInputs
, resolvedInputs = (,Coin 0) <$> inps
, outputs = outs
, withdrawals = mempty
}
, SealedTx bytes
)
Expand Down Expand Up @@ -243,7 +244,7 @@ genesisBlockFromTxOuts gp outs = Block
}
where
mkTx out@(TxOut (Address bytes) _) =
Tx (Hash $ blake2b256 bytes) [] [out]
Tx (Hash $ blake2b256 bytes) [] [out] mempty

dummyAddress
:: forall (n :: NetworkDiscriminant). (MaxSizeOf Address n ByronKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Cardano.Wallet.Api.Types
, ApiTransaction
, ApiWalletMigrationInfo
, DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, WalletStyle (..)
)
Expand Down Expand Up @@ -68,6 +69,7 @@ spec
, PaymentAddress n ByronKey
, EncodeAddress n
, DecodeAddress n
, DecodeStakeAddress n
)
=> SpecWith (Context t)
spec = do
Expand All @@ -87,6 +89,7 @@ spec = do
scenario_MIGRATE_01
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand All @@ -107,6 +110,7 @@ scenario_MIGRATE_01 fixtureSource = it title $ \ctx -> do
scenario_MIGRATE_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Cardano.Wallet.Api.Types
, ApiTxId (ApiTxId)
, ApiUtxoStatistics
, DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, Iso8601Time (..)
, WalletStyle (..)
Expand Down Expand Up @@ -108,6 +109,7 @@ spec
, PaymentAddress n ByronKey
, EncodeAddress n
, DecodeAddress n
, DecodeStakeAddress n
)
=> SpecWith (Context t)
spec = do
Expand Down Expand Up @@ -173,6 +175,7 @@ spec = do
scenario_TRANS_CREATE_01_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO ApiByronWallet)
Expand Down Expand Up @@ -258,6 +261,7 @@ scenario_TRANS_CREATE_01_02 fixtureSource fixtures = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_01_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO ApiByronWallet)
Expand Down Expand Up @@ -290,6 +294,7 @@ scenario_TRANS_ESTIMATE_01_02 fixtureSource fixtures = it title $ \ctx -> do
scenario_TRANS_CREATE_04b
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -312,6 +317,7 @@ scenario_TRANS_CREATE_04b = it title $ \ctx -> do
scenario_TRANS_CREATE_04c
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -334,6 +340,7 @@ scenario_TRANS_CREATE_04c = it title $ \ctx -> do
scenario_TRANS_CREATE_04d
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -356,6 +363,7 @@ scenario_TRANS_CREATE_04d = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_04b
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand Down Expand Up @@ -383,6 +391,7 @@ scenario_TRANS_ESTIMATE_04b = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_04c
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -405,6 +414,7 @@ scenario_TRANS_ESTIMATE_04c = it title $ \ctx -> do
scenario_TRANS_CREATE_07
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand All @@ -427,6 +437,7 @@ scenario_TRANS_CREATE_07 = it title $ \ctx -> do
scenario_RESTORE_01
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand Down Expand Up @@ -504,6 +515,7 @@ scenario_RESTORE_01 fixtureSource = it title $ \ctx -> do
scenario_RESTORE_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO (ApiByronWallet, [Address]))
Expand Down Expand Up @@ -561,6 +573,7 @@ scenario_RESTORE_02 fixtureTarget = it title $ \ctx -> do
scenario_RESTORE_03
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO (ApiByronWallet, [Address]))
Expand Down Expand Up @@ -601,6 +614,7 @@ scenario_RESTORE_03 fixtureTarget = it title $ \ctx -> do
scenario_TRANS_UTXO_01
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
)
=> (Context t -> IO ApiByronWallet)
Expand Down Expand Up @@ -646,6 +660,7 @@ scenario_TRANS_UTXO_01 fixtureSource fixtureTarget = it title $ \ctx -> do
scenario_TRANS_REG_1670
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand Down Expand Up @@ -723,6 +738,7 @@ scenario_TRANS_REG_1670 fixture = it title $ \ctx -> do
verifyTxInputsAndOutputs
:: forall (d :: NetworkDiscriminant).
( DecodeAddress d
, DecodeStakeAddress d
, EncodeAddress d
, PaymentAddress d IcarusKey
)
Expand All @@ -747,6 +763,7 @@ scenario_TRANS_REG_1670 fixture = it title $ \ctx -> do
fixtureCantCoverFee
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -764,6 +781,7 @@ fixtureCantCoverFee ctx = do
fixtureNotEnoughMoney
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -780,6 +798,7 @@ fixtureNotEnoughMoney ctx = do
fixtureWrongPassphrase
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -795,6 +814,7 @@ fixtureWrongPassphrase ctx = do
fixtureDeletedWallet
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand Down Expand Up @@ -831,6 +851,7 @@ mkPayment addr_ amnt = [json|
postByronTransaction
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
)
=> Context t
-- A surrounding API context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Cardano.Wallet.Api.Types
, ApiT (..)
, ApiTransaction
, DecodeAddress (..)
, DecodeStakeAddress (..)
, EncodeAddress (..)
, WalletStyle (..)
)
Expand Down Expand Up @@ -120,6 +121,7 @@ spec
, EncodeAddress n
, KnownCommand t
, DecodeAddress n
, DecodeStakeAddress n
)
=> SpecWith (Context t)
spec = describe "BYRON_TXS_CLI" $ do
Expand Down Expand Up @@ -486,6 +488,7 @@ spec = describe "BYRON_TXS_CLI" $ do
scenario_TRANS_CREATE_01_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, KnownCommand t
)
Expand Down Expand Up @@ -573,6 +576,7 @@ scenario_TRANS_CREATE_01_02 fixtureSource fixtures = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_01_02
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, KnownCommand t
)
Expand Down Expand Up @@ -610,6 +614,7 @@ scenario_TRANS_ESTIMATE_01_02 fixtureSource fixtures = it title $ \ctx -> do
scenario_TRANS_CREATE_04b
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
, KnownCommand t
Expand All @@ -633,6 +638,7 @@ scenario_TRANS_CREATE_04b = it title $ \ctx -> do
scenario_TRANS_CREATE_04c
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
, KnownCommand t
Expand All @@ -656,6 +662,7 @@ scenario_TRANS_CREATE_04c = it title $ \ctx -> do
scenario_TRANS_CREATE_04d
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
, KnownCommand t
Expand All @@ -679,6 +686,7 @@ scenario_TRANS_CREATE_04d = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_04b
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
, KnownCommand t
Expand Down Expand Up @@ -711,6 +719,7 @@ scenario_TRANS_ESTIMATE_04b = it title $ \ctx -> do
scenario_TRANS_ESTIMATE_04c
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
, KnownCommand t
Expand All @@ -734,6 +743,7 @@ scenario_TRANS_ESTIMATE_04c = it title $ \ctx -> do
scenario_TRANS_CREATE_07
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
, KnownCommand t
Expand Down Expand Up @@ -765,6 +775,7 @@ scenario_TRANS_CREATE_07 = it title $ \ctx -> do
fixtureCantCoverFee
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -782,6 +793,7 @@ fixtureCantCoverFee ctx = do
fixtureNotEnoughMoney
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -798,6 +810,7 @@ fixtureNotEnoughMoney ctx = do
fixtureWrongPassphrase
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n IcarusKey
)
Expand All @@ -813,6 +826,7 @@ fixtureWrongPassphrase ctx = do
fixtureDeletedWallet
:: forall (n :: NetworkDiscriminant) t.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ByronKey
)
Expand Down
Loading

0 comments on commit a844464

Please sign in to comment.