Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically test XDR type-switches #3430

Closed
2opremio opened this issue Mar 1, 2021 · 1 comment
Closed

Automatically test XDR type-switches #3430

2opremio opened this issue Mar 1, 2021 · 1 comment
Assignees
Labels
Milestone

Comments

@2opremio
Copy link
Contributor

2opremio commented Mar 1, 2021

In Horizon there are several places where we exhaustively go over union type tags.

e.g. 1 :

	switch operation.OperationType() {
	case xdr.OperationTypeCreateAccount:
		foo()
	case xdr.OperationTypeCreateAccount:
		bar()
	...
	}

e.g. 2 :

	switch effectType {
	case EffectTypeNames[EffectAccountCreated]:
		foo()
	case EffectTypeNames[EffectAccountCredited]:
		bar()
	...
	}

When adding new types (e.g. a new operation or effect) it's easy to miss updating some of those switches.

We should strive to create automatic unit tests which notify a case entry was missed whenever we add a new type.

@2opremio
Copy link
Contributor Author

2opremio commented Mar 1, 2021

For operation types we can use reflection, since we have all the symbol names are automatically generated in xdr.operationTypeMap .

For effects we can go over the keys of effects.EffectTypeNames.

We should do something similar for all the history.Effect* symbols, we can probably use resourceadapter.EffectTypeNames and even compare that the length of effects.EffectTypeNames and resourceadapter.EffectTypeNames (or remove that duplication once and for all).

We should do something, as well for horizon/operations.TypeNames (check that all the existing operations are present).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants