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

[#131] TZIP 12 Updates implementing storage views and storage field changes. #151

Merged
merged 8 commits into from
Jan 7, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

env:
FETCH_CONTRACT:
"mkdir -p haskell/test/resources/ && buildkite-agent artifact download stablecoin.tz haskell/test/resources/ && buildkite-agent artifact download stablecoin.fa1.2.tz haskell/test/resources/ && buildkite-agent artifact download metadata.tz haskell/test/resources/ && buildkite-agent artifact download tzip16-metadata.tz haskell/test/resources/ --step \"LIGO-contract\""
"mkdir -p haskell/test/resources/ && buildkite-agent artifact download stablecoin.tz haskell/test/resources/ && buildkite-agent artifact download stablecoin.fa1.2.tz haskell/test/resources/ && buildkite-agent artifact download metadata.tz haskell/test/resources/ --step \"LIGO-contract\""
TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER: "Y"

steps:
Expand Down Expand Up @@ -33,12 +33,10 @@ steps:
- nix-build -A tezos-contract-fa1-2 -o stablecoin.fa1.2_raw.tz
- nix run -f. morley -c morley optimize --contract stablecoin.fa1.2_raw.tz --output stablecoin.fa1.2.tz
- nix-build -A tezos-metadata-contract -o metadata.tz
- nix-build -A tezos-tzip16-metadata-contract -o tzip16-metadata.tz
artifact_paths:
- stablecoin.tz
- stablecoin.fa1.2.tz
- metadata.tz
- tzip16-metadata.tz

# wait for the contract step to complete, so the next steps can download generated contract
- wait
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ TAGS
/haskell/test/resources/stablecoin.tz
/haskell/test/resources/stablecoin.fa1.2.tz
/haskell/test/resources/metadata.tz
/haskell/test/resources/tzip16-metadata.tz
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ SPDX-License-Identifier: MIT
<!-- Don't forget to update the gas/transaction costs tables in the
README when a new version is released. -->

* [#151](https://github.com/tqtezos/stablecoin/pull/151)
* Remove `token_metadata_registry` entrypoint.
* Add TZIP-16 storage views as required by TZIP-12.

## 1.5.0

* [#144](https://github.com/tqtezos/stablecoin/pull/144)
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ build-ligo:
$(MAKE_LIGO) stablecoin.tz
$(MAKE_LIGO) stablecoin.fa1.2.tz
$(MAKE_LIGO) metadata.tz
$(MAKE_LIGO) tzip16-metadata.tz

# Compile LIGO contract and then build everything haskell-related (including tests and benchmarks)
# with development options.
Expand Down
9 changes: 1 addition & 8 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ let
buildPhase = "make metadata.tz";
installPhase = "cp metadata.tz $out";
};
tezos-tzip16-metadata-contract = pkgs.stdenv.mkDerivation {
name = "stablecoin.tz";
src = ./ligo;
nativeBuildInputs = [ ligo ];
buildPhase = "make tzip16-metadata.tz";
installPhase = "cp tzip16-metadata.tz $out";
};
tezos-client = (import "${sources.tezos-packaging}/nix/build/pkgs.nix" {}).ocamlPackages.tezos-client;

# nixpkgs has weeder 2, but we use weeder 1
Expand Down Expand Up @@ -118,5 +111,5 @@ in
test = project.stablecoin.components.tests.stablecoin-test;
nettest = project.stablecoin.components.tests.stablecoin-nettest;
stablecoin-client = project.stablecoin.components.exes.stablecoin-client;
inherit tezos-contract tezos-contract-fa1-2 tezos-metadata-contract tezos-tzip16-metadata-contract tezos-client pkgs weeder-script morley;
inherit tezos-contract tezos-contract-fa1-2 tezos-metadata-contract tezos-client pkgs weeder-script morley;
}
3 changes: 0 additions & 3 deletions haskell/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ define build_stablecoin_contract
$(MAKE_LIGO) stablecoin.tz
$(MAKE_LIGO) stablecoin.fa1.2.tz
$(MAKE_LIGO) metadata.tz
$(MAKE_LIGO) tzip16-metadata.tz
mkdir -p test/resources
$(MORLEY) optimize --contract "$(LIGO_DIR)/stablecoin.tz" --output "test/resources/stablecoin.tz"
$(MORLEY) optimize --contract "$(LIGO_DIR)/stablecoin.fa1.2.tz" --output "test/resources/stablecoin.fa1.2.tz"
cp "$(LIGO_DIR)/metadata.tz" "test/resources/metadata.tz"
cp "$(LIGO_DIR)/tzip16-metadata.tz" "test/resources/tzip16-metadata.tz"
endef

# Build everything haskell-related (including tests and benchmarks) with development options.
Expand Down Expand Up @@ -85,4 +83,3 @@ clean:
rm -f stablecoin.tz
rm -f stablecoin.fa1.2.tz
rm -f metadata.tz
rm -f tzip16-metadata.tz
8 changes: 3 additions & 5 deletions haskell/nettest/FA1_2Comparison.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Lorentz.Contracts.Spec.FA2Interface as FA2
import Lorentz.Contracts.Stablecoin as SFA2
import Lorentz.Contracts.StablecoinFA1_2 as SFA1_2

import Lorentz.Contracts.Test.Common (nettestOriginateContractMetadataContract, nettestOriginateMetadataRegistry)
import Lorentz.Contracts.Test.Common (nettestOriginateContractMetadataContract)

-- | This test originates both the FA1.2 and FA2 versions of stablecoin,
-- and performs a single @transfer@ operation.
Expand Down Expand Up @@ -49,7 +49,7 @@ fa1_2ComparisonScenario = uncapsNettest $ do
, rPendingOwner = Nothing
}

cmrFA1_2Address <- nettestOriginateContractMetadataContract SFA2.metadataJSON
cmrFA1_2Address <- nettestOriginateContractMetadataContract (SFA2.metadataJSON Nothing)
let fa1_2Storage = SFA1_2.Storage
{ sDefaultExpiry = 1000
, sLedger = BigMap balances
Expand All @@ -70,8 +70,7 @@ fa1_2ComparisonScenario = uncapsNettest $ do
comment "Calling transfer"
callFrom (AddressResolved owner1) fa1_2ContractAddr (Call @"Transfer") (#from .! owner1, #to .! owner2, #value .! 2)

mrAddress <- nettestOriginateMetadataRegistry
cmrAddress <- nettestOriginateContractMetadataContract SFA2.metadataJSON
cmrAddress <- nettestOriginateContractMetadataContract (SFA2.metadataJSON Nothing)
let fa2Storage = SFA2.Storage
{ sDefaultExpiry = 1000
, sLedger = BigMap balances
Expand All @@ -82,7 +81,6 @@ fa1_2ComparisonScenario = uncapsNettest $ do
, sRoles = roles
, sTransferlistContract = Nothing
, sOperators = mempty
, sTokenMetadataRegistry = mrAddress
, sMetadata = SFA2.metadataMap @(()) (RemoteContract cmrAddress)
, sTotalSupply = 0
}
Expand Down
13 changes: 5 additions & 8 deletions haskell/nettest/Nettest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ scNettestScenario originateTransferlist transferlistType = uncapsNettest $ do
operator <- newAddress "Some operator"
otherOperator <- newAddress "Other operator"

comment "Originating metadata contract"
cmrAddress <- nettestOriginateContractMetadataContract (metadataJSON Nothing)
let
originationParams =
addAccount (superuser , ([operator], 1110000))
Expand All @@ -62,19 +64,14 @@ scNettestScenario originateTransferlist transferlistType = uncapsNettest $ do
{ opOwner = nettestOwner
, opPauser = nettestPauser
, opMasterMinter = nettestMasterMinter
, opMetadataUri = RemoteContract cmrAddress
}

comment "Originating metadata registry contract"
mrAddress <- nettestOriginateMetadataRegistry

comment "Originating contract metadata contract"
cmrAddress <- nettestOriginateContractMetadataContract metadataJSON

comment "Originating stablecoin contract"
scAddress <-
originateUntypedSimple
"nettest.Stablecoin"
(untypeValue (toVal (mkInitialStorage originationParams mrAddress (Just cmrAddress))))
(untypeValue (toVal (mkInitialStorage originationParams)))
(T.convertContract stablecoinContract)

comment "Originating transferlist contract"
Expand Down Expand Up @@ -372,7 +369,7 @@ scNettestScenario originateTransferlist transferlistType = uncapsNettest $ do

-- We originate a new contract to make sure the minters list is empty
scAddress' <- do
let str = mkInitialStorage (originationParams { opMinters = mempty }) mrAddress (Just cmrAddress)
let str = mkInitialStorage (originationParams { opMinters = mempty })
originateUntypedSimple "nettest.Stablecoin_for_minter_test" (untypeValue $ toVal str) (T.convertContract stablecoinContract)

let
Expand Down
12 changes: 6 additions & 6 deletions haskell/nettest/Permit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import Morley.Nettest
import Lorentz.Contracts.Spec.FA2Interface (TransferDestination(..), TransferItem(..))
import qualified Lorentz.Contracts.Spec.FA2Interface as FA2
import Lorentz.Contracts.Stablecoin
(ConfigureMinterParam(..), Parameter(..), PermitParam(..), metadataJSON, mkPermitHash,
stablecoinContract)
(ConfigureMinterParam(..), MetadataUri(..), Parameter(..), PermitParam(..), metadataJSON,
mkPermitHash, stablecoinContract)

import Lorentz.Contracts.Test.Common
(OriginationParams(..), addAccount, defaultOriginationParams, mkInitialStorage,
nettestOriginateContractMetadataContract, nettestOriginateMetadataRegistry)
nettestOriginateContractMetadataContract, testFA2TokenMetadata)

permitScenario :: NettestScenario m
permitScenario = uncapsNettest $ do
Expand All @@ -32,16 +32,16 @@ permitScenario = uncapsNettest $ do
(_, user1) <- createUser "Steve"

comment "Originating contracts"
mrAddress <- nettestOriginateMetadataRegistry
cmrAddress <- nettestOriginateContractMetadataContract metadataJSON
cmrAddress <- nettestOriginateContractMetadataContract (metadataJSON $ Just testFA2TokenMetadata)
let originationParams =
addAccount (owner1 , ([], 1000)) $
defaultOriginationParams
{ opOwner = owner1
, opPauser = pauser
, opMasterMinter = masterMinter
, opMetadataUri = RemoteContract cmrAddress
}
storage = mkInitialStorage originationParams mrAddress (Just cmrAddress)
storage = mkInitialStorage originationParams
contract <- TAddress @Parameter <$> originateUntypedSimple
"nettest.Stablecoin"
(untypeValue (toVal storage))
Expand Down
8 changes: 2 additions & 6 deletions haskell/nettest/StablecoinClientTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module StablecoinClientTest
( stablecoinClientScenario
) where

import Michelson.Text (mt)
import Morley.Nettest as NT
import Tezos.Address (Address)
import Util.Named ((.!))
Expand All @@ -34,23 +33,20 @@ stablecoinClientScenario = do
(contractOwnerAlias, contractOwnerAddr, contractOwner) <- createRole "contract-owner"
(_, _, minter) <- createRole "minter"
(transferlistAlias, transferlistAddr, transferlist) <- createRole "transferlist"
(_, _, mdRegisty) <- createRole "metadata-registry"

comment "Deploying contract"
contractAddr <- deploy (#sender.! originator) InitialStorageData
{ isdMasterMinter = masterMinter
, isdContractOwner = contractOwner
, isdPauser = pauser
, isdTransferlist = Just transferlist
, isdTokenSymbol = [mt|a|]
, isdTokenName = [mt|b|]
, isdTokenSymbol = "a"
, isdTokenName = "b"
, isdTokenDecimals = 3
, isdTokenMetadataRegistry = Just mdRegisty
, isdDefaultExpiry = 1000
, isdContractMetadataStorage = OpRemoteContract
}
let contract = #contract .! AddressResolved contractAddr

comment "Testing get-balance"
actualBalance <- SC.getBalance contract
expectedBalance <- NT.getBalance (AddressResolved contractAddr)
Expand Down
29 changes: 16 additions & 13 deletions haskell/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extra-source-files:
- ChangeLog.md
- test/resources/stablecoin.tz
- test/resources/metadata.tz
- test/resources/tzip16-metadata.tz

synopsis: FA2-based tezos stablecoin smart contract
category: Blockchain
Expand Down Expand Up @@ -63,26 +62,27 @@ tests:

dependencies:
- aeson
- bytestring
- cleveland
- containers
- fmt
- hedgehog
- hspec
- interpolate
- lorentz
- morley
- morley-prelude
- morley-ledgers
- morley-ledgers-test
- morley-metadata
- lorentz
- cleveland
- morley-metadata-test
- morley-prelude
- mtl
- stablecoin
- tasty
- tasty-hedgehog
- tasty-hspec
- tasty-hunit-compat
- tasty-hedgehog
- hedgehog
- stablecoin
- hspec
- containers
- mtl
- fmt
- text
- bytestring
- interpolate

stablecoin-nettest:
<<: *test-common
Expand All @@ -98,7 +98,10 @@ tests:
- morley
- morley-client
- morley-ledgers
- morley-metadata
- morley-metadata-test
- morley-prelude
- optparse-applicative
- stablecoin
- text
- with-utf8
Loading