@@ -59,9 +59,10 @@ type Project struct {
5959 Persist bool
6060 Version string
6161 Accounts []struct {
62- ID string
63- Address string
64- DraftCode string
62+ ID string
63+ Address string
64+ DraftCode string
65+ DeployedCode string
6566 }
6667 TransactionTemplates []TransactionTemplate
6768 Secret string
@@ -103,6 +104,8 @@ query($projectId: UUID!) {
103104 accounts {
104105 id
105106 address
107+ draftCode
108+ deployedCode
106109 }
107110 }
108111}
@@ -1072,9 +1075,9 @@ func TestTransactionExecutions(t *testing.T) {
10721075 // manually construct resolver
10731076 store := memory .NewStore ()
10741077
1075- chain := blockchain .NewProjects (store , lru .New (128 ), initAccounts )
1078+ projects := blockchain .NewProjects (store , lru .New (128 ), initAccounts )
10761079 authenticator := auth .NewAuthenticator (store , sessionName )
1077- resolver := playground .NewResolver (version , store , authenticator , chain )
1080+ resolver := playground .NewResolver (version , store , authenticator , projects )
10781081
10791082 c := newClientWithResolver (resolver )
10801083
@@ -1106,7 +1109,7 @@ func TestTransactionExecutions(t *testing.T) {
11061109 eventA .Values [0 ],
11071110 )
11081111
1109- err = chain .Reset (& model.InternalProject {
1112+ err = projects .Reset (& model.InternalProject {
11101113 ID : uuid .MustParse (project .ID ),
11111114 })
11121115 require .NoError (t , err )
@@ -1799,6 +1802,74 @@ func TestAccounts(t *testing.T) {
17991802 assert .Contains (t , respB .UpdateAccount .DeployedContracts , "Foo" )
18001803 })
18011804
1805+ t .Run ("Update account and redeploy code" , func (t * testing.T ) {
1806+ c := newClient ()
1807+
1808+ project := createProject (t , c )
1809+
1810+ account := project .Accounts [0 ]
1811+
1812+ var respA GetAccountResponse
1813+
1814+ err := c .Post (
1815+ QueryGetAccount ,
1816+ & respA ,
1817+ client .Var ("projectId" , project .ID ),
1818+ client .Var ("accountId" , account .ID ),
1819+ )
1820+ require .NoError (t , err )
1821+
1822+ assert .Equal (t , "" , respA .Account .DeployedCode )
1823+
1824+ var respB UpdateAccountResponse
1825+
1826+ const contract = "pub contract Foo {}"
1827+
1828+ err = c .Post (
1829+ MutationUpdateAccountDeployedCode ,
1830+ & respB ,
1831+ client .Var ("projectId" , project .ID ),
1832+ client .Var ("accountId" , account .ID ),
1833+ client .Var ("code" , contract ),
1834+ client .AddCookie (c .SessionCookie ()),
1835+ )
1836+ require .NoError (t , err )
1837+
1838+ assert .Equal (t , contract , respB .UpdateAccount .DeployedCode )
1839+ assert .Contains (t , respB .UpdateAccount .DeployedContracts , "Foo" )
1840+
1841+ var respC UpdateAccountResponse
1842+
1843+ const contract2 = "pub contract Bar {}"
1844+
1845+ err = c .Post (
1846+ MutationUpdateAccountDeployedCode ,
1847+ & respC ,
1848+ client .Var ("projectId" , project .ID ),
1849+ client .Var ("accountId" , account .ID ),
1850+ client .Var ("code" , contract2 ),
1851+ client .AddCookie (c .SessionCookie ()),
1852+ )
1853+ require .NoError (t , err )
1854+
1855+ assert .Equal (t , contract2 , respC .UpdateAccount .DeployedCode )
1856+ assert .Contains (t , respC .UpdateAccount .DeployedContracts , "Bar" )
1857+
1858+ var resp GetProjectResponse
1859+
1860+ err = c .Post (
1861+ QueryGetProject ,
1862+ & resp ,
1863+ client .Var ("projectId" , project .ID ),
1864+ )
1865+ require .NoError (t , err )
1866+
1867+ assert .Equal (t , project .ID , resp .Project .ID )
1868+ assert .Len (t , resp .Project .Accounts , 5 )
1869+
1870+ assert .Equal (t , contract2 , resp .Project .Accounts [0 ].DeployedCode )
1871+ })
1872+
18021873 t .Run ("Update non-existent account" , func (t * testing.T ) {
18031874 c := newClient ()
18041875
0 commit comments