Skip to content

Commit

Permalink
Merge pull request #1538 from input-output-hk/feat/lw-11530-txbuild-d…
Browse files Browse the repository at this point in the history
…rep-retirement-should-prevent-withdraw-rewards

Feat/lw 11530 txbuild drep retirement should prevent withdraw rewards
  • Loading branch information
mchappell authored Dec 2, 2024
2 parents 379316d + 6362d83 commit 5cc45d0
Show file tree
Hide file tree
Showing 39 changed files with 894 additions and 139 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/continuous-integration-blockfrost-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
TEST_CLIENT_ASSET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:3015"}'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER: 'blockfrost'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:3015"}'
TEST_CLIENT_DREP_PROVIDER: 'blockfrost'
TEST_CLIENT_DREP_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:3015"}'
TEST_CLIENT_HANDLE_PROVIDER: 'http'
TEST_CLIENT_HANDLE_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4011/"}'
TEST_CLIENT_NETWORK_INFO_PROVIDER: 'blockfrost'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/continuous-integration-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
TEST_CLIENT_ASSET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4014/"}'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER: 'ws'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
TEST_CLIENT_DREP_PROVIDER: 'blockfrost'
TEST_CLIENT_DREP_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:3015"}'
TEST_CLIENT_HANDLE_PROVIDER: 'http'
TEST_CLIENT_HANDLE_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4011/"}'
TEST_CLIENT_NETWORK_INFO_PROVIDER: 'ws'
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/Cardano/types/DelegationsAndRewards.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DelegateRepresentative } from './Governance';
import { AlwaysAbstain, AlwaysNoConfidence } from './Governance';
import { DRepInfo } from '../../Provider';
import { Lovelace } from './Value';
import { Metadatum } from './AuxiliaryData';
import { PoolId, PoolIdHex, StakePool } from './StakePool';
Expand All @@ -24,7 +25,7 @@ export enum StakeCredentialStatus {
Unregistered = 'UNREGISTERED'
}

export type DRepDelegatee = { delegateRepresentative: DelegateRepresentative };
export type DRepDelegatee = { delegateRepresentative: DRepInfo | AlwaysAbstain | AlwaysNoConfidence };

export interface RewardAccountInfo {
address: RewardAccount;
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/Cardano/types/Governance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Crypto from '@cardano-sdk/crypto';
import { Credential, CredentialType, RewardAccount } from '../Address';
import { DRepInfo } from '../../Provider';
import { EpochNo, Fraction, ProtocolVersion, TransactionId } from '.';
import { Lovelace } from './Value';
import { ProtocolParametersUpdateConway } from './ProtocolParameters';
Expand Down Expand Up @@ -187,10 +188,14 @@ export type AlwaysNoConfidence = {

export type DelegateRepresentative = Credential | AlwaysAbstain | AlwaysNoConfidence;

export const isDRepCredential = (deleg: DelegateRepresentative): deleg is Credential => !('__typename' in deleg);
export const isDrepInfo = (drep: DelegateRepresentative | DRepInfo): drep is DRepInfo =>
'id' in drep && 'active' in drep;

export const isDRepAlwaysAbstain = (deleg: DelegateRepresentative): deleg is AlwaysAbstain =>
!isDRepCredential(deleg) && deleg.__typename === 'AlwaysAbstain';
export const isDRepCredential = (deleg: DelegateRepresentative | DRepInfo): deleg is Credential =>
'type' in deleg && 'hash' in deleg;

export const isDRepAlwaysNoConfidence = (deleg: DelegateRepresentative): deleg is AlwaysNoConfidence =>
!isDRepCredential(deleg) && deleg.__typename === 'AlwaysNoConfidence';
export const isDRepAlwaysAbstain = (deleg: DelegateRepresentative | DRepInfo): deleg is AlwaysAbstain =>
'__typename' in deleg && deleg.__typename === 'AlwaysAbstain';

export const isDRepAlwaysNoConfidence = (deleg: DelegateRepresentative | DRepInfo): deleg is AlwaysNoConfidence =>
'__typename' in deleg && deleg.__typename === 'AlwaysNoConfidence';
2 changes: 2 additions & 0 deletions packages/e2e/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ TEST_CLIENT_ASSET_PROVIDER=http
TEST_CLIENT_ASSET_PROVIDER_PARAMS='{"baseUrl":"http://localhost:4014/"}'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER=ws
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS='{"baseUrl":"http://localhost:4000/"}'
TEST_CLIENT_DREP_PROVIDER='blockfrost'
TEST_CLIENT_DREP_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
TEST_CLIENT_HANDLE_PROVIDER=http
TEST_CLIENT_HANDLE_PROVIDER_PARAMS='{"baseUrl":"http://localhost:4011/"}'
TEST_CLIENT_NETWORK_INFO_PROVIDER=ws
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ KEY_MANAGEMENT_PROVIDER=inMemory
KEY_MANAGEMENT_PARAMS='{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "passphrase":"some_passphrase","mnemonic":""}'
TEST_CLIENT_ASSET_PROVIDER=http
TEST_CLIENT_ASSET_PROVIDER_PARAMS='{"baseUrl":"http://localhost:4000"}'
TEST_CLIENT_DREP_PROVIDER='blockfrost'
TEST_CLIENT_DREP_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER=http
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS='{"baseUrl":"http://localhost:4000"}'
TEST_CLIENT_NETWORK_INFO_PROVIDER=http
Expand Down
4 changes: 4 additions & 0 deletions packages/e2e/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ const validators = {
TEST_CLIENT_ASSET_PROVIDER_PARAMS: providerParams(),
TEST_CLIENT_CHAIN_HISTORY_PROVIDER: str(),
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS: providerParams(),
TEST_CLIENT_DREP_PROVIDER: str({ choices: ['blockfrost'] }),
TEST_CLIENT_DREP_PROVIDER_PARAMS: providerParams(),
TEST_CLIENT_HANDLE_PROVIDER: str(),
TEST_CLIENT_HANDLE_PROVIDER_PARAMS: providerParams(),
TEST_CLIENT_NETWORK_INFO_PROVIDER: str(),
Expand Down Expand Up @@ -145,6 +147,8 @@ export const walletVariables = [
'TEST_CLIENT_ASSET_PROVIDER_PARAMS',
'TEST_CLIENT_CHAIN_HISTORY_PROVIDER',
'TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS',
'TEST_CLIENT_DREP_PROVIDER',
'TEST_CLIENT_DREP_PROVIDER_PARAMS',
'TEST_CLIENT_HANDLE_PROVIDER',
'TEST_CLIENT_HANDLE_PROVIDER_PARAMS',
'KEY_MANAGEMENT_PARAMS',
Expand Down
26 changes: 26 additions & 0 deletions packages/e2e/src/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
AssetProvider,
Cardano,
ChainHistoryProvider,
DRepProvider,
HandleProvider,
NetworkInfoProvider,
ProviderFactory,
Expand All @@ -39,6 +40,7 @@ import {
BlockfrostAssetProvider,
BlockfrostChainHistoryProvider,
BlockfrostClient,
BlockfrostDRepProvider,
BlockfrostNetworkInfoProvider,
BlockfrostRewardsProvider,
BlockfrostTxSubmitProvider,
Expand Down Expand Up @@ -81,6 +83,7 @@ export type CreateKeyAgent = (dependencies: KeyAgentDependencies) => Promise<Asy
export const keyManagementFactory = new ProviderFactory<CreateKeyAgent>();
export const assetProviderFactory = new ProviderFactory<AssetProvider>();
export const chainHistoryProviderFactory = new ProviderFactory<ChainHistoryProvider>();
export const drepProviderFactory = new ProviderFactory<DRepProvider>();
export const networkInfoProviderFactory = new ProviderFactory<NetworkInfoProvider>();
export const rewardsProviderFactory = new ProviderFactory<RewardsProvider>();
export const txSubmitProviderFactory = new ProviderFactory<TxSubmitProvider>();
Expand Down Expand Up @@ -181,6 +184,19 @@ chainHistoryProviderFactory.register(BLOCKFROST_PROVIDER, async (params: any, lo
});
});

drepProviderFactory.register(BLOCKFROST_PROVIDER, async (params: any, logger): Promise<DRepProvider> => {
if (params.baseUrl === undefined) throw new Error(`${BlockfrostDRepProvider.name}: ${MISSING_URL_PARAM}`);

return new Promise<DRepProvider>(async (resolve) => {
resolve(
new BlockfrostDRepProvider(
new BlockfrostClient({ baseUrl: params.baseUrl }, { rateLimiter: { schedule: (task) => task() } }),
logger
)
);
});
});

networkInfoProviderFactory.register(
HTTP_PROVIDER,
async (params: any, logger: Logger): Promise<NetworkInfoProvider> => {
Expand Down Expand Up @@ -483,6 +499,11 @@ export const getWallet = async (props: GetWalletProps) => {
env.TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS,
logger
),
drepProvider: await drepProviderFactory.create(
env.TEST_CLIENT_DREP_PROVIDER,
env.TEST_CLIENT_DREP_PROVIDER_PARAMS,
logger
),
handleProvider: await handleProviderFactory.create(
env.TEST_CLIENT_HANDLE_PROVIDER,
env.TEST_CLIENT_HANDLE_PROVIDER_PARAMS,
Expand Down Expand Up @@ -571,6 +592,11 @@ export const getSharedWallet = async (props: GetSharedWalletProps) => {
env.TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS,
logger
),
drepProvider: await drepProviderFactory.create(
env.TEST_CLIENT_DREP_PROVIDER,
env.TEST_CLIENT_DREP_PROVIDER_PARAMS,
logger
),
handleProvider: await handleProviderFactory.create(
env.TEST_CLIENT_HANDLE_PROVIDER,
env.TEST_CLIENT_HANDLE_PROVIDER_PARAMS,
Expand Down
3 changes: 3 additions & 0 deletions packages/e2e/src/scripts/generate-dotenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ TEST_CLIENT_ASSET_PROVIDER=http
TEST_CLIENT_ASSET_PROVIDER_PARAMS='{\"baseUrl\":\"${url}\"}'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER=ws
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS='{\"baseUrl\":\"${url}\"}'
TEST_CLIENT_DREP_PROVIDER: 'blockfrost'
# TODO: use blockfrost URL
TEST_CLIENT_DREP_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:3015"}'
TEST_CLIENT_HANDLE_PROVIDER=http
TEST_CLIENT_HANDLE_PROVIDER_PARAMS='{\"baseUrl\":\"${url}\"}'
TEST_CLIENT_NETWORK_INFO_PROVIDER=ws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
assetProviderFactory,
bip32Ed25519Factory,
chainHistoryProviderFactory,
drepProviderFactory,
getEnv,
getLoadTestScheduler,
keyManagementFactory,
Expand Down Expand Up @@ -55,6 +56,11 @@ const getProviders = async () => ({
env.TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS,
logger
),
drepProvider: await drepProviderFactory.create(
env.TEST_CLIENT_DREP_PROVIDER,
env.TEST_CLIENT_DREP_PROVIDER_PARAMS,
logger
),
networkInfoProvider: await networkInfoProviderFactory.create(
env.TEST_CLIENT_NETWORK_INFO_PROVIDER,
env.TEST_CLIENT_NETWORK_INFO_PROVIDER_PARAMS,
Expand Down
Loading

0 comments on commit 5cc45d0

Please sign in to comment.