diff --git a/java/google/registry/model/registry/Registry.java b/java/google/registry/model/registry/Registry.java index 98cb50e85..a56efb6e3 100644 --- a/java/google/registry/model/registry/Registry.java +++ b/java/google/registry/model/registry/Registry.java @@ -826,15 +826,19 @@ public class Registry extends ImmutableObject implements Buildable { checkArgument( instance.getServerStatusChangeCost().getCurrencyUnit().equals(instance.currency), "Server status change cost must be in the registry's currency"); + Predicate currencyCheck = new Predicate(){ + @Override + public boolean apply(Money money) { + return money.getCurrencyUnit().equals(instance.currency); + }}; checkArgument( Iterables.all( - instance.getRenewBillingCostTransitions().values(), - new Predicate(){ - @Override - public boolean apply(Money money) { - return money.getCurrencyUnit().equals(instance.currency); - }}), + instance.getRenewBillingCostTransitions().values(), currencyCheck), "Renew cost must be in the registry's currency"); + checkArgument( + Iterables.all( + instance.eapFeeSchedule.toValueMap().values(), currencyCheck), + "All EAP fees must be in the registry's currency"); checkArgumentNotNull( instance.pricingEngineClassName, "All registries must have a configured pricing engine"); instance.tldStrId = tldName; diff --git a/java/google/registry/tools/CreateTldCommand.java b/java/google/registry/tools/CreateTldCommand.java index c0d8058f3..af7baf641 100644 --- a/java/google/registry/tools/CreateTldCommand.java +++ b/java/google/registry/tools/CreateTldCommand.java @@ -30,6 +30,7 @@ import com.beust.jcommander.Parameters; import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldState; +import org.joda.money.CurrencyUnit; import org.joda.money.Money; import javax.annotation.Nullable; @@ -73,9 +74,17 @@ class CreateTldCommand extends CreateOrUpdateTldCommand { void setCommandSpecificProperties(Registry.Builder builder) { // Pick up the currency from the create cost. Since all costs must be in one currency, and that // condition is enforced by the builder, it doesn't matter which cost we choose it from. - builder.setCurrency(createBillingCost != null + CurrencyUnit currency = createBillingCost != null ? createBillingCost.getCurrencyUnit() - : Registry.DEFAULT_CURRENCY); + : Registry.DEFAULT_CURRENCY; + + builder.setCurrency(currency); + + // If this is a non-default currency, set the EAP fee schedule to a matching currency. + // TODO(b/29089413): once we have a flag for this, don't do this check if the flag is set. + if (currency != Registry.DEFAULT_CURRENCY) { + builder.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(currency))); + } } @Override diff --git a/javatests/google/registry/model/registry/RegistryTest.java b/javatests/google/registry/model/registry/RegistryTest.java index 61bf1c5f5..0b3a6dda0 100644 --- a/javatests/google/registry/model/registry/RegistryTest.java +++ b/javatests/google/registry/model/registry/RegistryTest.java @@ -434,4 +434,13 @@ public class RegistryTest extends EntityTestCase { assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2))).isEqualTo(Money.of(USD, 0)); assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2))).isEqualTo(Money.of(USD, 50)); } + + @Test + public void testFailure_eapFee_wrongCurrency() { + thrown.expect( + IllegalArgumentException.class, "All EAP fees must be in the registry's currency"); + Registry.get("tld").asBuilder() + .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) + .build(); + } }